I have the following JSON
{ "nest1" : { "attributes" : { "type" : "irrelevant", "url" : "irrelevant" }, "key" : "value1" }, "nest2" : { "attributes" : { "type" : "irrelevant", "url" : "irrelevant" }, "key" : "value2" } } I have tried something like below to grab the value for the secondkey, but this throws an InvalidOperationException. with the following error message:
Cannot access child value on Newtonsoft.Json.Linq.JProperty.
string value = getJson(json, "key"); The method looks like
public string getJson(string json, string name) { JObject token = JObject.Parse(json); JToken jtoken = token.Last.ToString(); return jtoken[name].toString(); } I'm guessing there is probably something simple i'm forgetting, any help would be great