Windows Phone开发之Json数据解析

对于Json数据的应用,现在变得越来越简单了,只要有Json数据,引用最近的Json的DLL资源即可调用Json方法,DLL资源是一种封装好的一系列的函数,直接读取数据。
部分内容引用自:

http://blog.csdn.net/fengyun1989/article/details/7342029

Json格式数据:

{"weatherinfo":{"city":"北京","city_en":"beijing","date_y":"2012年3月11日","date":"","week":"星期日","fchh":"11","cityid":"101010100","temp1":"6℃~-6℃","temp2":"9℃~-2℃","temp3":"13℃~0℃","temp4":"11℃~-1℃","temp5":"9℃~1℃"}}

添加Json引用:
Json最近Dll:http://json.codeplex.com/
下载后解压,找到Newtonsoft.Json.dll放到合适的文件夹,添加引用即可。
解析Json数据:

void wb_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
  {
 //用Jobject解析json数据
            JObject json = JObject.Parse(e.Result);
            weather = new WeatherInfo{

                city = (string)json["weatherinfo"]["city"],
                cityid = (string)json["weatherinfo"]["cityid"],
                date_y = (string)json["weatherinfo"]["date_y"],
                week = (string)json["weatherinfo"]["week"],
                info = (string)json["weatherinfo"]["index_d"],
                wind1 = (string)json["weatherinfo"]["wind1"],
                temp1 = (string)json["weatherinfo"]["temp1"],
                temp2 = (string)json["weatherinfo"]["temp2"],
                temp3 = (string)json["weatherinfo"]["temp3"],
                temp4 = (string)json["weatherinfo"]["temp4"],
                weather1 = (string)json["weatherinfo"]["weather1"],
                weather2 = (string)json["weatherinfo"]["weather2"],
                weather3 = (string)json["weatherinfo"]["weather3"],
                weather4 = (string)json["weatherinfo"]["weather4"]

            };
}

解释如下:
wb_DownloadStringCompleted是Web Service的调用函数,e.Result表示返回结果,即上文中的Json格式数据的内容。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值