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

{"status":1,"detail":"\u6570\u636e\u83b7\u53d6\u6210\u529f","data":[[{"date":"2014-01-01","dis_id":"1119","dis_name":"\u5f90\u5dde\u5e02","url":"http:\/\/www.tianqiyubao.com\/local.php?dis_id=1119","weather":"1","wind":"\u897f\u98ce3-4\u7ea7","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":"\u5f90\u5dde\u5e02","url":"http:\/\/www.tianqiyubao.com\/local.php?dis_id=1119","weather":"1","wind":"\u897f\u98ce3-4\u7ea7","weather_name":"\u6674","weather_pic":"styles\/images\/icon2\/day\/1.png","humidity":"","tem":"13"},{"date":"2014-01-01","dis_id":"1119","dis_name":"\u5f90\u5dde\u5e02","url":"http:\/\/www.tianqiyubao.com\/local.php?dis_id=1119","weather":"1","wind":"\u5317\u98ce3-4\u7ea7","weather_name":"\u6674","weather_pic":"styles\/images\/icon2\/night\/1.png","humidity":"","tem":"1"}]}]]}

结果就老报一个错误。

Cannot deserialize JSON array (i.e. [,,]) 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 , position .

google之发现一个问题和我很相似,也就没细想就照着写了。写完之后发现还是报错。两个问题链接如下:

http://stackoverflow.com/questions/9452901/cannot-deserialize-json-array-into-type-json-net

http://stackoverflow.com/questions/5224697/deserializing-json-when-sometimes-array-and-sometimes-object

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

原实体类:

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

正确无误了。

[Cannot deserialize JSON array into type] NewtonSoft.Json解析数据出错原因的更多相关文章

  1. asp.net core 3.0 JObject The collection type 'Newtonsoft.Json.Linq.JObject' is not supported

    在asp.net core 3.0 中,如果直接在Controller中返回 Jobject 类型,会抛出如下错误: The collection type 'Newtonsoft.Json.Linq ...

  2. DataTable转Json字符串(使用Newtonsoft.Json.dll)

    DataTable转Json字符串(使用Newtonsoft.Json.dll) 在需要把DataTable转为Json字符串时,自己手动拼接太麻烦,而且容易出错,费时费力,使用Newtonsoft. ...

  3. Can not add Newtonsoft.Json.Linq.JValue to Newtonsoft.Json.Linq.JObject.

    https://blog.csdn.net/zhouyingge1104/article/details/83307637 C#项目中使用NewtonSoft.json,报错提示: Can not a ...

  4. Poco::JSON::Array 中object 设置preserveInsertionOrder 时,stringify出错-->深入解析

    在使用poco version 1.6.0时 Poco::JSON::Array 在object  设置preserveInsertionOrder =true 时 调用 array.stringif ...

  5. .NET C# Json序列化与反序列化——Newtonsoft.Json学习笔记

    Newtonsoft.Json,一款.NET中开源的Json序列化和反序列化类库(介绍及下载地址:http://json.codeplex.com/). /// <summary>    ...

  6. C# 后台通过网络地址访问百度地图取回当前在地图上的经纬度,并将取回的复杂Json格式字符串反序列化(Newtonsoft.Json)

    直接上代码:解释都在代码中 ak 要自己去百度地图申请. 其中申请ak的时候,有个属性render直接填*就行. namespace HampWebControl 是我的空间命名! namespace ...

  7. WP8解析JSON格式(使用Newtonsoft.Json包)

    DOTA2 WebAPI请求返回的格式有两种,一种是XML,一种是JSON,默认是返回JSON格式. 这里举一个简单的解析JSON格式的例子(更多JSON操作): { "response&q ...

  8. Json的反序列化 .net Newtonsoft.Json

    项目中有个.json文件. { "instances": [ { "name": "baidu", "url": &qu ...

  9. Newtonsoft.Json C# Json序列化和反序列化工具的使用、类型方法大全 C# 算法题系列(二) 各位相加、整数反转、回文数、罗马数字转整数 C# 算法题系列(一) 两数之和、无重复字符的最长子串 DateTime Tips c#发送邮件,可发送多个附件 MVC图片上传详解

    Newtonsoft.Json C# Json序列化和反序列化工具的使用.类型方法大全   Newtonsoft.Json Newtonsoft.Json 是.Net平台操作Json的工具,他的介绍就 ...

随机推荐

  1. HP proliant服务器从usb启动

    1,开机出现自检画面开始按F9进入设置,进入BIOS 选择standard boot order(rpl),把usb driver放在第一位,保存好 2,按F1开始启动. (注:我使用ubuntu14 ...

  2. mybatis 处理 mysql 表中的 text类型的 字段

    在mysql 中 text类型的字段: service_detail text NULL 服务描述   . 对应java文件中 model 中的 String:  private String ser ...

  3. java项目学习

    GitHub地址:https://github.com/zhanglei-workspace/shopping-management-system

  4. 如果 date_field = TRUNC(date_field) 就说明时分秒为0(也就是不包含),否则就包含时分秒

    如果 date_field = TRUNC(date_field) 就说明时分秒为0(也就是不包含),否则就包含时分秒

  5. iOS-tableView会卡顿

    其实影响tableView卡顿的因素有很多,我也就其中一些常见的问题来说一下. 在tableView里的tableViewCell中使用许多图片的时候,而且我们大量使用的是 xxx.clipsToBo ...

  6. VC的CListCtrl控件

    1. CListCtrl 样式及设置 2. 扩展样式设置 3. 数据插入 4. 一直选中Item 5. 选中和取消选中Item 6. 得到CListCtrl中所有行的checkbox的状态 7. 得到 ...

  7. pre 布局

    w

  8. 2015-03-11——简析DOM规范

    DOM 0级指浏览器专有的,非标准的方法.对象和集合. DOM 1级 1998年发布包括:DOM coreDOM html DOM 2级 DOM2 core 2000年发布  DOM2 html 20 ...

  9. Python 实现获取【昨天】【今天】【明天】日期

    昨天 from datetime import date, timedelta yesterday = (date.today() + timedelta(days=-1)).strftime(&qu ...

  10. 流畅的python 字典和集合

    介绍 dict 类型不但在各种程序里广泛使用,它也是 Python 语言的基石.模块的命名空间.实例的属性和函数的关键字参数中都可以看到字典的身影.跟它有关的内置函数都在 __builtins__._ ...