This is the json string that I want to parse. Im using the default Json functions available in Windows 8
JSON value:
"{\"updated_at\":1405482225,\"settings\":{\"conception_mode\":1,\"app_lock_string\":\"\",\"user_cycle_length\":21,\"week_starts_monday\":1}}"
My sample code:
JsonObject test1 = JsonObject.Parse(received);
var timestamp = test1.GetNamedValue("updated_at").GetNumber();
settingsTimestamp = (long)(Convert.ToDouble(timestamp));
string settingString = test1.GetNamedValue("settings").GetString();//ERROR
JsonObject settingsVal = JsonObject.Parse(settingString);
I get the "updated_at" value but when I try to retrieve "settings", it is throwing exception saying, it is not a string.
For windows phone, I have done using JSON.NET library, so things were a little easier. How do I parse this in Windows8
settings is a JSON object. So you can use GetObject directly:
JsonObject settingsVal = test1.GetNamedValue( "settings" ).GetObject();
来源:https://stackoverflow.com/questions/24772509/parse-json-using-windows-data-json-in-windows-8-c-sharp