今天用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; }

正确无误了。

最新文章

  1. 入门: 使用JNI 从C++代码中调用Java的静态方法
  2. VBA 按照文件类型名称打开一个文件
  3. Oracle中alter system命令参数之scope
  4. NSString、NSData、char* 类型之间的转换-备
  5. 基于RAF的一个小动画框
  6. nth-child 和nth-type的区别
  7. Apache Kafka系列(五) Kafka Connect及FileConnector示例
  8. coursea机器学习课程作业
  9. Unity配置安卓开发环境
  10. anoconda包管理汇总
  11. c/c++ 线性表之双向链表
  12. 高斯模糊的Java实现
  13. 代码之髓读后感——类&amp;继承
  14. 设置div背景透明的CSS样式
  15. CM记录-操作系统调优
  16. malloc调用后经历了什么?
  17. Fibonacci(矩阵)
  18. Properties类和如何操作属性
  19. c++ mktime()
  20. uva 11971 Polygon

热门文章

  1. 一站式WPF--依赖属性(DependencyProperty)二
  2. Chem 3D中怎么创建立体模型
  3. python入门(一):基础语法
  4. iOS-如何在项目中使用CocoaPods
  5. spring boot打包会有.war.original文件的原因 (笔记)
  6. 【BZOJ2259】[Oibh]新型计算机 最短路
  7. java的double类型如何精确到一位小数?
  8. mysql返回字符串在另外一个字符串中第n次出现的方法。
  9. js 中和c类似
  10. Java 之多线程通信(等待/唤醒)