C# targetting ARM: How to deserialize JSON? C# targetting ARM: How to deserialize JSON? json json

C# targetting ARM: How to deserialize JSON?


The JSON on the Watch view is really just for display, but it's already in the type JsonObject as shown in the Type column.

It's saying that the method will not work because the type you are trying to extract cannot be handled by GetNamedString() and GetNamedObject(). You should have a GetNamedValue() method too which will handle the number:

meme.GetNamedValue("views").GetNumber()

You can also access the value through the index like this:

meme["views"].GetNumber()

If you want to make sure it doesn't fail for edge cases in terms of returned JSON values, you can use the meme["whateverJSONkey"].ValueType property and switch/case on that to prevent exceptions


I don't know why JSON.NET didn't work, but the following compiles and executes just fine (async-ness left out for brevity):

string s = @"{    ""date"":""2017-07-09"",  ""period"":""year"",  ""views"":970347,  ""visitors"":150013,  ""likes"":136,  ""reblogs"":13,  ""comments"":1099,  ""followers"":145}";JsonObject data = null;if (!JsonObject.TryParse(s, out data))  new MessageDialog("Not valid JSON").ShowAsync();var followers = data["followers"].GetNumber();var visitors = data["visitors"].GetNumber();new MessageDialog(String.Format("You had {0} visitors and {1} followers",  visitors, followers)).ShowAsync();