Quantcast
Channel: Safe JSON navigation - Stack Overflow
Browsing index pages (2 articles)
↧

Safe JSON navigation

Is there a way to navigate a JSON safely?Given this JSON,{"foo": { "bar": { "baz": "quz" } } }I'd like to navigate it safely similar to the line below without creating types for all of them.string...

View Article


Answer by StriplingWarrior for Safe JSON navigation

For the exact syntax you mention, you can cast your JObject as dynamic.var jObj = JsonConvert.DeserializeObject<dynamic>(text);string value1 = jObj.foo?.bar?.baz ?? "default";Here's a LINQPad...

View Article

Browsing index pages (2 articles)


Latest Images