newtonsoft.json解析天气数据出错解决方法
时间:2022-03-10 12:23:21
今天用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. [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,json
0
投稿
猜你喜欢
Java面试题解析之判断以及防止SQL注入
2023-05-26 18:08:59
android ListView结合xutils3仿微信实现下拉加载更多
2023-11-29 11:11:50
Java多线程synchronized同步方法详解
2023-06-30 00:39:42
Springboot打包为Docker镜像并部署的实现
2023-06-05 23:11:52
java中重载,继承,重写和多态的区别
2022-05-06 06:40:16
Spring MVC结合Spring Data JPA实现按条件查询和分页
2023-03-04 07:24:36
Java 批量删除Word中的空白段落示例代码
2023-09-17 16:36:53
Spring MVC+FastJson+hibernate-validator整合的完整实例教程
2021-10-31 13:20:13
Java 基础语法
2021-09-21 19:26:32
Spring+SpringMVC+MyBatis深入学习及搭建(二)之MyBatis原始Dao开发和mapper代理开发
2021-07-24 06:36:00
Spring Cloud Eureka 注册与发现操作步骤详解
2022-06-25 07:11:12
Android编程实现向桌面添加快捷方式的方法
2023-01-24 02:10:33
HelloSpringMVC注解版实现步骤解析
2021-07-21 01:58:42
Android使用TextView跑马灯效果
2022-05-20 20:07:20
Qt QTableWidget基本操作及使用
2022-05-22 23:15:55
Java程序中实现调用Python脚本的方法详解
2021-07-08 22:00:08
java开发ServiceLoader实现机制及SPI应用
2022-12-24 09:55:05
android中Glide实现加载图片保存至本地并加载回调监听
2021-12-05 23:00:03
详解C++设计模式编程中建造者模式的实现
2022-10-25 01:33:20
Android依赖注入框架Dagger2的使用方法
2021-12-19 20:25:39