我需要解析这个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