我需要解析這個JSON字符串到我的「WeatherJson」類型的對象。但是我不知道如何解析字符串中的數組,如''weather':[{"id":802,"main":"Clouds","description":"scattered clouds","icon":"03d"}]
。實體類將是什麼樣子?如何解析這個JSON結果作爲一個對象?
JSON字符串:
{
"coord": {"lon":79.85,"lat":6.93},
"sys": {
"type": 1,
"id": 7864,
"message": 0.0145,
"country": "LK",
"sunrise": 1435883361,
"sunset": 1435928421
},
"weather": [
{"id":802, "main":"Clouds", "description":"scattered clouds", "icon":"03d"}
],
"base": "stations",
"main": {
"temp": 302.15,
"pressure": 1013,
"humidity": 79,
"temp_min": 302.15,
"temp_max": 302.15
},
"visibility":10000,
"wind": { "speed": 4.1, "deg": 220 },
"clouds": { "all": 40 },
"dt": 1435893000,
"id":1248991,
"name":"Colombo",
"cod":200
}
編輯
我需要檢索從代碼以下值:
WeatherJson w = new WeatherJson();
Console.WriteLine(w.weather.description);
//that above line was retrieved and stored from the JSONArray named 'weather' in the main json response
那麼你的'WeatherJson'類型是什麼樣子?你有一些代碼已經嘗試解析?如果是這樣,當你嘗試時會發生什麼? –
看看這個[如何分析在C#中的json] [1] [1]:http://stackoverflow.com/a/6620173/1129313 – Garry
我不知道如何解析正常JSON數據如:消息「:0.0145。我的問題是檢索數組並將其存儲在對象@JonSkeet – Dinuka