Skip to content

Instantly share code, notes, and snippets.

@beachside-project
Last active April 15, 2016 11:46
Show Gist options
  • Save beachside-project/523a503a5f00925b4a9f3b81caaa87b0 to your computer and use it in GitHub Desktop.
Save beachside-project/523a503a5f00925b4a9f3b81caaa87b0 to your computer and use it in GitHub Desktop.
jsonDemo_main1
class Program
{
static void Main(string[] args)
{
var shinobu = new Person()
{
FirstName = "shinobu",
LastName = "oshino",
Age = 598,
Favorites = new[] { "golden chocolate", "pon de ring" },
Phones = new List<Phone>()
{
new Phone() {PhoneNumber = "000-000-111",ModelName = "Lumia"},
new Phone() {PhoneNumber = "111-000-000",ModelName = "Nokia"}
}
};
//Serialize、シンプル♪
var shinobuJson = JsonConvert.SerializeObject(shinobu, Formatting.Indented);
Console.WriteLine(shinobuJson);
//Jsonにインデントつけるには...
var shinobuJsonWithIndention = JsonConvert.SerializeObject(shinobu, Formatting.Indented);
Console.WriteLine(shinobuJsonWithIndention);
//Deserializeもシンプル♪
var shinobuModel = JsonConvert.DeserializeObject<Person>(shinobuJson);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment