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è)方框號(hào),原來(lái)是自己實(shí)體類(lèi)的設(shè)計(jì)有問(wèn)題,
原實(shí)體類(lèi):
public string status { get; set; }
public string detail { get; set; }
public List<MoreDayWeatherInfoFullDay> data { get; set;
更正后的實(shí)體類(lèi):
public string status { get; set; }
public string detail { get; set; }
public List<List<MoreDayWeatherInfoFullDay>> data { get; set; }
正確無(wú)誤了。
相關(guān)文章
C#實(shí)現(xiàn)TIF圖像轉(zhuǎn)PDF文件的方法
這篇文章主要介紹了C#實(shí)現(xiàn)TIF圖像轉(zhuǎn)PDF文件的方法,涉及C#使用TIFtoPDF工具實(shí)現(xiàn)pdf文件轉(zhuǎn)換的技巧,需要的朋友可以參考下2015-07-07
c# Invoke和BeginInvoke 區(qū)別分析
這篇文章主要介紹了c# Invoke和BeginInvoke 區(qū)別分析,需要的朋友可以參考下2014-10-10
C#使用Socket實(shí)現(xiàn)發(fā)送和接收?qǐng)D片的方法
這篇文章主要介紹了C#使用Socket實(shí)現(xiàn)發(fā)送和接收?qǐng)D片的方法,涉及C#操作socket發(fā)送與接收文件的使用技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-04-04
淺談C# 非模式窗體show()和模式窗體showdialog()的區(qū)別
下面小編就為大家?guī)?lái)一篇淺談C# 非模式窗體show()和模式窗體showdialog()的區(qū)別。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-07-07
C#封裝一個(gè)快速讀取寫(xiě)入操作excel的工具類(lèi)
這篇文章主要為大家詳細(xì)介紹了C#如何封裝一個(gè)快速讀取寫(xiě)入操作excel的工具類(lèi),文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2024-01-01
C#用ComboBox控件實(shí)現(xiàn)省與市的聯(lián)動(dòng)效果的方法
這篇文章主要介紹了C#用ComboBox控件實(shí)現(xiàn)省與市的聯(lián)動(dòng)效果的方法,較為詳細(xì)的分析了ComboBox控件的使用原理與相關(guān)技巧,需要的朋友可以參考下2015-01-01

