http://stackoverflow.com/questions/43577696/getting-nested-json-element-returns-an-error

CSharp · Console

/Program.cs

using System;
using System.Net;
using Newtonsoft.Json.Linq;
					
public class Program
{
	public static void Main()
	{
		using (WebClient wc = new WebClient())
		{
			var json = wc.DownloadString("https://randomuser.me/api/");
			JToken token = JToken.Parse(json);
			string firstName = (string)token.SelectToken("results[0].name.first");
			string lastName = (string)token.SelectToken("results[0].name.last");
			string city = (string)token.SelectToken("results[0].location.city");
			string username = (string)token.SelectToken("results[0].login.username");
			
			Console.WriteLine("First name: " + firstName);
			Console.WriteLine("Last name: " + lastName);
			Console.WriteLine("City: " + city);
			Console.WriteLine("Username: " + username);
		}
	}
}
;