在Windows 8 C#中使用Windows.Data.Json解析Json [英] Parse Json using Windows.Data.Json in Windows 8 C#

查看:834
本文介绍了在Windows 8 C#中使用Windows.Data.Json解析Json的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我要解析的json字符串.我正在使用Windows 8中提供的默认Json功能

This is the json string that I want to parse. Im using the default Json functions available in Windows 8

JSON值:

"{\"updated_at\":1405482225,\"settings\":{\"conception_mode\":1,\"app_lock_string\":\"\",\"user_cycle_length\":21,\"week_starts_monday\":1}}"

我的示例代码:

 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);

我得到了"updated_at"值,但是当我尝试检索设置"时,它抛出异常,说它不是字符串.

I get the "updated_at" value but when I try to retrieve "settings", it is throwing exception saying, it is not a string.

对于Windows Phone,我已经使用JSON.NET库完成了,所以事情变得容易一些.如何在Windows8中解析此内容

For windows phone, I have done using JSON.NET library, so things were a little easier. How do I parse this in Windows8

推荐答案

设置是JSON对象.因此,您可以直接使用GetObject:

settings is a JSON object. So you can use GetObject directly:

JsonObject settingsVal = test1.GetNamedValue( "settings" ).GetObject();

这篇关于在Windows 8 C#中使用Windows.Data.Json解析Json的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆