StackOverflow Q33088462

CSharp · Console

/Program.cs

using System;
using Newtonsoft.Json;	
using Newtonsoft.Json.Linq;
					
public class Program
{
	public static void Main()
	{
		string json = @"
		{
			""name"" : ""Joe Shmoe"",
			""age"" : 26,
			""picture"":
			{
				""id"": 123456,
				""data"":
				{
					""type"": ""jpg"",
					""url"": ""http://www.someplace.com/mypicture.jpg""
				}
			}
		}";
	
		JObject jo = JObject.Parse(json);
		Person p = jo.ToObject<Person>();
		p.ProfilePicture = (string)jo.SelectToken("picture.data.url");

		Console.WriteLine(p.Name);
		Console.WriteLine(p.Age);
		Console.WriteLine(p.ProfilePicture);
	}
}

class Person
{
	[JsonProperty("name")]
	public string Name { get; set; }
	
	[JsonProperty("age")]
	public int Age { get; set; }
	
	public string ProfilePicture { get; set; }
}
;