当前位置:  编程技术>.net/c#/asp.net

newtonsoft.json解析天气数据出错解决方法

    来源: 互联网  发布时间:2014-10-29

    本文导语:  今天用NewtonSoft.JSon解析一个天气数据,数据格式如: 代码如下:{"status":1,"detail":"u6570u636eu83b7u53d6u6210u529f","data":[[{"date":"2014-01-01","dis_id":"1119","dis_name":"u5f90u5ddeu5e02","url":"http://www.tianqiyubao.com/local.php?dis_id=1119","weather":"1","wind":"u897fu9...

今天用NewtonSoft.JSon解析一个天气数据,数据格式如:

代码如下:

{"status":1,"detail":"u6570u636eu83b7u53d6u6210u529f","data":[[{"date":"2014-01-01","dis_id":"1119","dis_name":"u5f90u5ddeu5e02","url":"http://www.tianqiyubao.com/local.php?dis_id=1119","weather":"1","wind":"u897fu98ce3-4u7ea7","weather_name":"u6674","weather_pic":"styles/images/icon2/day/1.png","humidity":"","tem_min":"1","tem_max":"13","sunrise":"07:17","sunset":"17:12","pm":"109","air":"u826f","day_night":[{"date":"2014-01-01","dis_id":"1119","dis_name":"u5f90u5ddeu5e02","url":"http://www.tianqiyubao.com/local.php?dis_id=1119","weather":"1","wind":"u897fu98ce3-4u7ea7","weather_name":"u6674","weather_pic":"styles/images/icon2/day/1.png","humidity":"","tem":"13"},{"date":"2014-01-01","dis_id":"1119","dis_name":"u5f90u5ddeu5e02","url":"http://www.tianqiyubao.com/local.php?dis_id=1119","weather":"1","wind":"u5317u98ce3-4u7ea7","weather_name":"u6674","weather_pic":"styles/images/icon2/night/1.png","humidity":"","tem":"1"}]}]]}

结果就老报一个错误。

代码如下:

Cannot deserialize JSON array (i.e. [1,2,3]) into type 'SweetWeather.MoreDayWeatherInfoFullDay'.
The deserialized type must be an array or implement a collection interface like IEnumerable, ICollection or IList.
To force JSON arrays to deserialize add the JsonArrayAttribute to the type. Path 'data[0]', line 1, position 69.

最后还是报错。仔细发现有两个方框号,原来是自己实体类的设计有问题,

原实体类:

代码如下:

public string status { get; set; }
public string detail { get; set; }
public List data { get; set;

更正后的实体类:

代码如下:

public string status { get; set; }
public string detail { get; set; }
public List data { get; set; }

正确无误了。


    
 
 

您可能感兴趣的文章:

 
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。












  • 相关文章推荐


  • 站内导航:


    特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

    ©2012-2021,,E-mail:www_#163.com(请将#改为@)

    浙ICP备11055608号-3