這是我的JSON:如何在.Net中解析這個JSON的特定數據?
{
"coord": {
"lon": -0.13,
"lat": 51.51
},
"weather": [{
"id": 520,
"main": "Rain",
"description": "light intensity shower rain",
"icon": "09d"
}],
"base": "stations",
"main": {
"temp": 289.42,
"pressure": 1008,
"humidity": 55,
"temp_min": 287.15,
"temp_max": 291.15
},
"visibility": 10000,
"wind": {
"speed": 4.1,
"deg": 340
},
"rain": {
"1h": 4.32
},
"clouds": {
"all": 40
},
"dt": 1463937214,
"sys": {
"type": 1,
"id": 5091,
"message": 0.0474,
"country": "GB",
"sunrise": 1463889474,
"sunset": 1463947050
},
"id": 2643743,
"name": "London",
"cod": 200
}
我想反序列化到天氣預報類此。我只對這部分數據感興趣。
"main":{"temp":289.42,"pressure":1008,"humidity":55,"temp_min":287.15,"temp_max":291.15}
所以我想創建一個類,像下面
class weather
{
var temp,pressure,humidity,..
}
可能有人請告知我怎麼可以在這裏使用DeserializeObject?
你從哪裏得到JSON,你是從文件中讀取它?從網絡請求獲取它?這是在一個WebApi或MVC應用程序的上下文中,還是僅僅是一個? –