今天用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. 时间戳(Unix时间)

    /// <summary> /// 时间戳与DateTime互转 /// </summary> public class UnixOfTimeHelper { /// < ...

  2. WPFLoading遮层罩

    一直想实现这么个功能来着,所以去网上搜了资料,复杂的看不懂,后来挑了一个最简单的,复用了这位大神的很多代码(大神看到了别打脸).这位大神是用UserControl,使用时则是调用用户控件中的方法.之前 ...

  3. iOS开发之--蓝牙开发实战

    转载自:http://www.cnblogs.com/zyjzyj/p/6029968.html ,感谢英杰 前言 最近一直在开发关于蓝牙的功能,本来是不想写这一篇文章,因为网上关于ios蓝牙开发的文 ...

  4. Delphi xe7 android实现透明度可以调整的对话框

    Delphi xe7 android实现透明度可以调整的对话框 Delphi xe7 android实现透明度可以调整的对话框 Delphi xe7 android实现透明度可以调整的对话框 要实现对 ...

  5. mysql如何判断一个字符串是否包含另外一个字符串?

    转自:http://blog.csdn.net/hechurui/article/details/49278493 判断子字符串在父字符串当中的索引: SELECT LOCATE("b&qu ...

  6. (转)SPDY

    SPDY:Google开发的基于传输控制协议(TCP)的应用层协议,目前已经被用于Google Chrome浏览器中来访问Google的SSL加密服务.SPDY并不是一种用于替代HTTP的协议,而是对 ...

  7. 第12章—整合Redis

    spring boot 系列学习记录:http://www.cnblogs.com/jinxiaohang/p/8111057.html 码云源码地址:https://gitee.com/jinxia ...

  8. GetWindowThreadProcessId

    函数功能:该函数返回创建指定窗口线程的标识和创建窗口的进程的标识符,后一项是可选的. 函数原型:DWORD GetWindowThreadProcessld(HWND hwnd,LPDWORD lpd ...

  9. DHTML 简介

    DHTML, 动态的 html, 不是一门语言, 是多项技术综合体的简称.其中包括了 html, CSS, DOM, javascript. HTML : 负责提供标签, 对数据进行封装,目的是便于对 ...

  10. Redis的Python客户端redis-py说明文档(转)

    add by zhj: 对Publish / Subscribe,LUA Scripting,Sentinel support,Scan Iterators等部分没有翻译,需要的用户参见英文原文吧.另 ...