newtonsoft.json解析天氣數(shù)據(jù)出錯(cuò)解決方法
今天用NewtonSoft.JSon解析一個(gè)天氣數(shù)據(jù),數(shù)據(jù)格式如:
{"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"}]}]]}
結(jié)果就老報(bào)一個(gè)錯(cuò)誤。
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.
最后還是報(bào)錯(cuò)。仔細(xì)發(fā)現(xiàn)有兩個(gè)方框號,原來是自己實(shí)體類的設(shè)計(jì)有問題,
原實(shí)體類:
public string status { get; set; }
public string detail { get; set; }
public List<MoreDayWeatherInfoFullDay> data { get; set;
更正后的實(shí)體類:
public string status { get; set; }
public string detail { get; set; }
public List<List<MoreDayWeatherInfoFullDay>> data { get; set; }
正確無誤了。
相關(guān)文章
Unity3D實(shí)現(xiàn)人物轉(zhuǎn)向與移動(dòng)
這篇文章主要為大家詳細(xì)介紹了Unity3D實(shí)現(xiàn)人物轉(zhuǎn)向與移動(dòng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-01-01C# WinForm捕獲全局變量異常 SamWang解決方法
本文將介紹C# WinForm捕獲全局變量異常 SamWang解決方法,需要的朋友可以參考2012-11-11C#中Thread(線程)和Task(任務(wù))實(shí)例詳解
.NET Framework在System.Threading命名空間中具有與線程相關(guān)的類,線程是一小組可執(zhí)行指令,這篇文章主要給大家介紹了關(guān)于C#中Thread(線程)和Task(任務(wù))的相關(guān)資料,需要的朋友可以參考下2022-03-03C# Redis學(xué)習(xí)系列(一)Redis下載安裝使用
這篇文章主要為大家分享了C# Redis學(xué)習(xí)系列教程第一篇, Redis下載、安裝、使用,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-05-05Unity3D實(shí)現(xiàn)攝像機(jī)鏡頭移動(dòng)并限制角度
這篇文章主要為大家詳細(xì)介紹了Unity3D實(shí)現(xiàn)攝像機(jī)鏡頭移動(dòng)并限制角度,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-05-05C#訪問SQL Server數(shù)據(jù)庫的實(shí)現(xiàn)方法
這篇文章主要介紹了C#訪問SQL Server數(shù)據(jù)庫的實(shí)現(xiàn)方法,以實(shí)例形式簡單分析了C#連接、查詢SQL Server數(shù)據(jù)庫的具體技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-10-10c# 使用Task實(shí)現(xiàn)非阻塞式的I/O操作
這篇文章主要介紹了c# 使用Task實(shí)現(xiàn)非阻塞式的I/O操作,幫助大家更好的理解和學(xué)習(xí)c# 編程語言,感興趣的朋友可以了解下2020-11-11