Parse Json using Windows.Data.Json in Windows 8 C#

风流意气都作罢 提交于 2019-12-06 17:32:21

问题


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


回答1:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!