手机
当前位置:查字典教程网 >编程开发 >C#教程 >newtonsoft.json解析天气数据出错解决方法
newtonsoft.json解析天气数据出错解决方法
摘要:今天用NewtonSoft.JSon解析一个天气数据,数据格式如:复制代码代码如下:{"status":1,"detail":"u6570u...

今天用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<MoreDayWeatherInfoFullDay> data { get; set;

更正后的实体类:

复制代码 代码如下:

public string status { get; set; }

public string detail { get; set; }

public List<List<MoreDayWeatherInfoFullDay>> data { get; set; }

正确无误了。

【newtonsoft.json解析天气数据出错解决方法】相关文章:

C#实现对AES加密和解密的方法

C#中Web.Config加密与解密的方法

C#删除文件目录或文件的解决方法

用C#对ADO.NET数据库完成简单操作的方法

Response.Redirect 正在中止线程解决方案

C# 大数据导出word的假死报错的处理方法

解析c#在未出现异常情况下查看当前调用堆栈的解决方法

c# 获取数据库中所有表名称的方法

c#.net 常用函数和方法集

基于使用递归推算指定位数的斐波那契数列值的解决方法

精品推荐
分类导航