using Newtonsoft.Json.Linq;
[JsonProperty(PropertyName = "DataTree")]
public Foo Data { get; set; }
[JsonProperty(PropertyName = "Location1")]
public string MyString1 { get; set; }
[JsonProperty(PropertyName = "Location2")]
public string MyString2 { get; set; }
public override string ToString()
=> $"{{ MyString1 = \"{MyString1}\", MyString2 = \"{MyString2}\" }}";
static void Main() => new Program().Run();
static string JsonString =
Name : 'Malcolm Reynolds',
Location2 : 'Independents',
Location2: 'House Madrassa',
var records = JsonConvert.DeserializeObject<Record[]>(JsonString);
var records = JArray.Parse(JsonString);
var dataTree = records[0].SelectToken("DataTree");
MyString1 = dataTree["Location1"].Value<string>(),
MyString2 = dataTree["Location2"].Value<string>(),
Foo UseLinqForJsonAndClasses()
var records = JArray.Parse(JsonString);
return records[0].SelectToken("DataTree").ToObject<Foo>();
Console.WriteLine(UseClasses());
Console.WriteLine(UseLinqForJson());
Console.WriteLine(UseLinqForJsonAndClasses());