Saturday, November 9, 2013

Navigate hierarchies of what was once JSON when deserializing with Newtonsoft in C#.

To cast the value of "bar" to a string when "bar" sits inside "foo" which sits inside the greater JSON object you are to deserialize in C#:

JObject jObject = (JObject)JsonConvert.DeserializeObject(serialization);
string bar = jObject["foo"]["bar"].ToString();

No comments:

Post a Comment