简体   繁体   English

如何从C#中的json字符串获取特定数据?

[英]How to get specific data from json string in c#?

I have a json string which is a api response: 我有一个api响应的json字符串:

{
  "response": {
  "version":"0.1",
  "termsofService":"http://www.wunderground.com/weather/api/d/terms.html",
  "features": {
  "forecast10day": 1
  }
    }
        ,
    "forecast":{
        "txt_forecast": {
        "date":"5:51 AM PDT",
        "forecastday": [
        {
        "period":0,
        "icon":"fog",
        "icon_url":"http://icons.wxug.com/i/c/k/fog.gif",
        "title":"Monday",
        "fcttext":"Foggy early, becoming sunny this afternoon. High 71F. Winds NNW at 10 to 15 mph.",
        "fcttext_metric":"Partly cloudy skies. High 22C. Winds NNW at 15 to 25 km/h.",
        "pop":"0"
        }
        ,
        {
        "period":1,
        "icon":"nt_mostlycloudy",
        "icon_url":"http://icons.wxug.com/i/c/k/nt_mostlycloudy.gif",
        "title":"Monday Night",
        "fcttext":"Partly cloudy early followed by cloudy skies overnight. Low 56F. Winds WNW at 10 to 15 mph.",
        "fcttext_metric":"Partly cloudy skies this evening will become overcast overnight. Low 13C. Winds WNW at 10 to 15 km/h.",
        "pop":"0"
        }
        ,
        {
        "period":2,
        "icon":"cloudy",
        "icon_url":"http://icons.wxug.com/i/c/k/cloudy.gif",
        "title":"Tuesday",
        "fcttext":"Cloudy. Slight chance of an afternoon shower. High 67F. Winds NNW at 5 to 10 mph.",
        "fcttext_metric":"Overcast. Slight chance of an afternoon shower. High around 20C. Winds NW at 10 to 15 km/h.",
        "pop":"20"
        }
        ,
        {
        "period":3,
        "icon":"nt_cloudy",
        "icon_url":"http://icons.wxug.com/i/c/k/nt_cloudy.gif",
        "title":"Tuesday Night",
        "fcttext":"Cloudy. Slight chance of a rain shower. Low 59F. Winds NW at 5 to 10 mph.",
        "fcttext_metric":"Cloudy. Slight chance of a rain shower. Low around 15C. Winds NW at 10 to 15 km/h.",
        "pop":"20"
        }
        ,
        {
        "period":4,
        "icon":"chancerain",
        "icon_url":"http://icons.wxug.com/i/c/k/chancerain.gif",
        "title":"Wednesday",
        "fcttext":"Rain showers early with some sunshine later in the day. High near 65F. Winds W at 10 to 20 mph. Chance of rain 40%.",
        "fcttext_metric":"Showers in the morning, then partly cloudy in the afternoon. High 19C. Winds W at 15 to 30 km/h. Chance of rain 40%.",
        "pop":"40"
        }
        ,
        {
        "period":5,
        "icon":"nt_clear",
        "icon_url":"http://icons.wxug.com/i/c/k/nt_clear.gif",
        "title":"Wednesday Night",
        "fcttext":"Mostly clear skies. Low 57F. Winds NW at 10 to 15 mph.",
        "fcttext_metric":"Generally fair. Low 14C. Winds NW at 15 to 25 km/h.",
        "pop":"10"
        }
        ,
        {
        "period":6,
        "icon":"partlycloudy",
        "icon_url":"http://icons.wxug.com/i/c/k/partlycloudy.gif",
        "title":"Thursday",
        "fcttext":"Some clouds in the morning will give way to mainly sunny skies for the afternoon. High 67F. Winds NW at 15 to 25 mph.",
        "fcttext_metric":"Some clouds in the morning will give way to mainly sunny skies for the afternoon. High around 20C. Winds NW at 25 to 40 km/h.",
        "pop":"10"
        }
        ,
        {
        "period":7,
        "icon":"nt_clear",
        "icon_url":"http://icons.wxug.com/i/c/k/nt_clear.gif",
        "title":"Thursday Night",
        "fcttext":"Mostly clear. Low 57F. Winds NNW at 10 to 20 mph.",
        "fcttext_metric":"Mostly clear. Low 14C. Winds NNW at 15 to 30 km/h.",
        "pop":"0"
        }
        ,
        {
        "period":8,
        "icon":"clear",
        "icon_url":"http://icons.wxug.com/i/c/k/clear.gif",
        "title":"Friday",
        "fcttext":"Mainly sunny. High 73F. Winds NNW at 10 to 20 mph.",
        "fcttext_metric":"Abundant sunshine. High 23C. Winds NNW at 15 to 30 km/h.",
        "pop":"0"
        }
        ,
        {
        "period":9,
        "icon":"nt_clear",
        "icon_url":"http://icons.wxug.com/i/c/k/nt_clear.gif",
        "title":"Friday Night",
        "fcttext":"A mostly clear sky. Low 58F. Winds NNW at 10 to 15 mph.",
        "fcttext_metric":"A mostly clear sky. Low 14C. Winds NNW at 10 to 15 km/h.",
        "pop":"0"
        }
        ,
        {
        "period":10,
        "icon":"clear",
        "icon_url":"http://icons.wxug.com/i/c/k/clear.gif",
        "title":"Saturday",
        "fcttext":"Mainly sunny. High 71F. NE winds shifting to NW at 10 to 15 mph.",
        "fcttext_metric":"Sunny skies. High 22C. NE winds shifting to NW at 15 to 25 km/h.",
        "pop":"0"
        }
        ,
        {
        "period":11,
        "icon":"nt_clear",
        "icon_url":"http://icons.wxug.com/i/c/k/nt_clear.gif",
        "title":"Saturday Night",
        "fcttext":"Partly cloudy. Low 57F. Winds WNW at 10 to 15 mph.",
        "fcttext_metric":"A few clouds overnight. Low 14C. Winds WNW at 10 to 15 km/h.",
        "pop":"10"
        }
        ,
        {
        "period":12,
        "icon":"partlycloudy",
        "icon_url":"http://icons.wxug.com/i/c/k/partlycloudy.gif",
        "title":"Sunday",
        "fcttext":"Partly cloudy skies. High near 65F. Winds WNW at 10 to 20 mph.",
        "fcttext_metric":"Some clouds in the morning will give way to mainly sunny skies for the afternoon. High 19C. Winds WNW at 15 to 30 km/h.",
        "pop":"10"
        }
        ,
        {
        "period":13,
        "icon":"nt_clear",
        "icon_url":"http://icons.wxug.com/i/c/k/nt_clear.gif",
        "title":"Sunday Night",
        "fcttext":"Clear to partly cloudy. Low around 55F. Winds NW at 10 to 20 mph.",
        "fcttext_metric":"Clear to partly cloudy. Low 13C. Winds NW at 15 to 30 km/h.",
        "pop":"10"
        }
        ,
        {
        "period":14,
        "icon":"partlycloudy",
        "icon_url":"http://icons.wxug.com/i/c/k/partlycloudy.gif",
        "title":"Monday",
        "fcttext":"Wind increasing. A few clouds from time to time. High 62F. Winds NW at 20 to 30 mph.",
        "fcttext_metric":"Wind increasing. A few clouds from time to time. High 17C. Winds NW at 30 to 50 km/h.",
        "pop":"10"
        }
        ,
        {
        "period":15,
        "icon":"nt_clear",
        "icon_url":"http://icons.wxug.com/i/c/k/nt_clear.gif",
        "title":"Monday Night",
        "fcttext":"Partly cloudy. Low 52F. Winds NW at 15 to 25 mph.",
        "fcttext_metric":"A few clouds overnight. Low 11C. Winds NW at 25 to 40 km/h.",
        "pop":"10"
        }
        ,
        {
        "period":16,
        "icon":"partlycloudy",
        "icon_url":"http://icons.wxug.com/i/c/k/partlycloudy.gif",
        "title":"Tuesday",
        "fcttext":"Partly cloudy skies. High 63F. Winds NW at 15 to 25 mph.",
        "fcttext_metric":"Some clouds in the morning will give way to mainly sunny skies for the afternoon. High 18C. Winds NW at 25 to 40 km/h.",
        "pop":"0"
        }
        ,
        {
        "period":17,
        "icon":"nt_clear",
        "icon_url":"http://icons.wxug.com/i/c/k/nt_clear.gif",
        "title":"Tuesday Night",
        "fcttext":"Mostly clear. Low 52F. Winds NNW at 10 to 20 mph.",
        "fcttext_metric":"A mostly clear sky. Low 11C. Winds NNW at 15 to 30 km/h.",
        "pop":"0"
        }
        ,
        {
        "period":18,
        "icon":"clear",
        "icon_url":"http://icons.wxug.com/i/c/k/clear.gif",
        "title":"Wednesday",
        "fcttext":"Mainly sunny. High around 65F. Winds N at 10 to 20 mph.",
        "fcttext_metric":"Mainly sunny. High 19C. Winds N at 15 to 30 km/h.",
        "pop":"0"
        }
        ,
        {
        "period":19,
        "icon":"nt_clear",
        "icon_url":"http://icons.wxug.com/i/c/k/nt_clear.gif",
        "title":"Wednesday Night",
        "fcttext":"Mainly clear early, then a few clouds later on. Low 52F. Winds N at 10 to 15 mph.",
        "fcttext_metric":"Mainly clear early, then a few clouds later on. Low 11C. Winds N at 15 to 25 km/h.",
        "pop":"0"
        }
        ]
        },
        "simpleforecast": {
        "forecastday": [
        {"date":{
    "epoch":"1445911200",
    "pretty":"7:00 PM PDT on October 26, 2015",
    "day":26,
    "month":10,
    "year":2015,
    "yday":298,
    "hour":19,
    "min":"00",
    "sec":0,
    "isdst":"1",
    "monthname":"October",
    "monthname_short":"Oct",
    "weekday_short":"Mon",
    "weekday":"Monday",
    "ampm":"PM",
    "tz_short":"PDT",
    "tz_long":"America/Los_Angeles"
},
        "period":1,
        "high": {
        "fahrenheit":"71",
        "celsius":"22"
        },
        "low": {
        "fahrenheit":"56",
        "celsius":"13"
        },
        "conditions":"Fog",
        "icon":"fog",
        "icon_url":"http://icons.wxug.com/i/c/k/fog.gif",
        "skyicon":"",
        "pop":0,
        "qpf_allday": {
        "in": 0.00,
        "mm": 0
        },
        "qpf_day": {
        "in": 0.00,
        "mm": 0
        },
        "qpf_night": {
        "in": 0.00,
        "mm": 0
        },
        "snow_allday": {
        "in": 0.0,
        "cm": 0.0
        },
        "snow_day": {
        "in": 0.0,
        "cm": 0.0
        },
        "snow_night": {
        "in": 0.0,
        "cm": 0.0
        },
        "maxwind": {
        "mph": 15,
        "kph": 24,
        "dir": "NNW",
        "degrees": 345
        },
        "avewind": {
        "mph": 11,
        "kph": 18,
        "dir": "NNW",
        "degrees": 345
        },
        "avehumidity": 76,
        "maxhumidity": 0,
        "minhumidity": 0
        }
        ,
        {"date":{
    "epoch":"1445997600",
    "pretty":"7:00 PM PDT on October 27, 2015",
    "day":27,
    "month":10,
    "year":2015,
    "yday":299,
    "hour":19,
    "min":"00",
    "sec":0,
    "isdst":"1",
    "monthname":"October",
    "monthname_short":"Oct",
    "weekday_short":"Tue",
    "weekday":"Tuesday",
    "ampm":"PM",
    "tz_short":"PDT",
    "tz_long":"America/Los_Angeles"
},
        "period":2,
        "high": {
        "fahrenheit":"67",
        "celsius":"19"
        },
        "low": {
        "fahrenheit":"59",
        "celsius":"15"
        },
        "conditions":"Overcast",
        "icon":"cloudy",
        "icon_url":"http://icons.wxug.com/i/c/k/cloudy.gif",
        "skyicon":"",
        "pop":20,
        "qpf_allday": {
        "in": 0.01,
        "mm": 0
        },
        "qpf_day": {
        "in": 0.00,
        "mm": 0
        },
        "qpf_night": {
        "in": 0.00,
        "mm": 0
        },
        "snow_allday": {
        "in": 0.0,
        "cm": 0.0
        },
        "snow_day": {
        "in": 0.0,
        "cm": 0.0
        },
        "snow_night": {
        "in": 0.0,
        "cm": 0.0
        },
        "maxwind": {
        "mph": 10,
        "kph": 16,
        "dir": "NNW",
        "degrees": 329
        },
        "avewind": {
        "mph": 9,
        "kph": 14,
        "dir": "NNW",
        "degrees": 329
        },
        "avehumidity": 72,
        "maxhumidity": 0,
        "minhumidity": 0
        }
        ,
        {"date":{
    "epoch":"1446084000",
    "pretty":"7:00 PM PDT on October 28, 2015",
    "day":28,
    "month":10,
    "year":2015,
    "yday":300,
    "hour":19,
    "min":"00",
    "sec":0,
    "isdst":"1",
    "monthname":"October",
    "monthname_short":"Oct",
    "weekday_short":"Wed",
    "weekday":"Wednesday",
    "ampm":"PM",
    "tz_short":"PDT",
    "tz_long":"America/Los_Angeles"
},
        "period":3,
        "high": {
        "fahrenheit":"65",
        "celsius":"18"
        },
        "low": {
        "fahrenheit":"57",
        "celsius":"14"
        },
        "conditions":"Chance of Rain",
        "icon":"chancerain",
        "icon_url":"http://icons.wxug.com/i/c/k/chancerain.gif",
        "skyicon":"",
        "pop":40,
        "qpf_allday": {
        "in": 0.04,
        "mm": 1
        },
        "qpf_day": {
        "in": 0.04,
        "mm": 1
        },
        "qpf_night": {
        "in": 0.00,
        "mm": 0
        },
        "snow_allday": {
        "in": 0.0,
        "cm": 0.0
        },
        "snow_day": {
        "in": 0.0,
        "cm": 0.0
        },
        "snow_night": {
        "in": 0.0,
        "cm": 0.0
        },
        "maxwind": {
        "mph": 20,
        "kph": 32,
        "dir": "W",
        "degrees": 269
        },
        "avewind": {
        "mph": 13,
        "kph": 21,
        "dir": "W",
        "degrees": 269
        },
        "avehumidity": 78,
        "maxhumidity": 0,
        "minhumidity": 0
        }
        ,
        {"date":{
    "epoch":"1446170400",
    "pretty":"7:00 PM PDT on October 29, 2015",
    "day":29,
    "month":10,
    "year":2015,
    "yday":301,
    "hour":19,
    "min":"00",
    "sec":0,
    "isdst":"1",
    "monthname":"October",
    "monthname_short":"Oct",
    "weekday_short":"Thu",
    "weekday":"Thursday",
    "ampm":"PM",
    "tz_short":"PDT",
    "tz_long":"America/Los_Angeles"
},
        "period":4,
        "high": {
        "fahrenheit":"67",
        "celsius":"19"
        },
        "low": {
        "fahrenheit":"57",
        "celsius":"14"
        },
        "conditions":"Partly Cloudy",
        "icon":"partlycloudy",
        "icon_url":"http://icons.wxug.com/i/c/k/partlycloudy.gif",
        "skyicon":"",
        "pop":10,
        "qpf_allday": {
        "in": 0.00,
        "mm": 0
        },
        "qpf_day": {
        "in": 0.00,
        "mm": 0
        },
        "qpf_night": {
        "in": 0.00,
        "mm": 0
        },
        "snow_allday": {
        "in": 0.0,
        "cm": 0.0
        },
        "snow_day": {
        "in": 0.0,
        "cm": 0.0
        },
        "snow_night": {
        "in": 0.0,
        "cm": 0.0
        },
        "maxwind": {
        "mph": 25,
        "kph": 40,
        "dir": "NW",
        "degrees": 319
        },
        "avewind": {
        "mph": 17,
        "kph": 27,
        "dir": "NW",
        "degrees": 319
        },
        "avehumidity": 78,
        "maxhumidity": 0,
        "minhumidity": 0
        }
        ,
        {"date":{
    "epoch":"1446256800",
    "pretty":"7:00 PM PDT on October 30, 2015",
    "day":30,
    "month":10,
    "year":2015,
    "yday":302,
    "hour":19,
    "min":"00",
    "sec":0,
    "isdst":"1",
    "monthname":"October",
    "monthname_short":"Oct",
    "weekday_short":"Fri",
    "weekday":"Friday",
    "ampm":"PM",
    "tz_short":"PDT",
    "tz_long":"America/Los_Angeles"
},
        "period":5,
        "high": {
        "fahrenheit":"73",
        "celsius":"23"
        },
        "low": {
        "fahrenheit":"58",
        "celsius":"14"
        },
        "conditions":"Clear",
        "icon":"clear",
        "icon_url":"http://icons.wxug.com/i/c/k/clear.gif",
        "skyicon":"",
        "pop":0,
        "qpf_allday": {
        "in": 0.00,
        "mm": 0
        },
        "qpf_day": {
        "in": 0.00,
        "mm": 0
        },
        "qpf_night": {
        "in": 0.00,
        "mm": 0
        },
        "snow_allday": {
        "in": 0.0,
        "cm": 0.0
        },
        "snow_day": {
        "in": 0.0,
        "cm": 0.0
        },
        "snow_night": {
        "in": 0.0,
        "cm": 0.0
        },
        "maxwind": {
        "mph": 20,
        "kph": 32,
        "dir": "NNW",
        "degrees": 347
        },
        "avewind": {
        "mph": 15,
        "kph": 24,
        "dir": "NNW",
        "degrees": 347
        },
        "avehumidity": 50,
        "maxhumidity": 0,
        "minhumidity": 0
        }
        ,
        {"date":{
    "epoch":"1446343200",
    "pretty":"7:00 PM PDT on October 31, 2015",
    "day":31,
    "month":10,
    "year":2015,
    "yday":303,
    "hour":19,
    "min":"00",
    "sec":0,
    "isdst":"1",
    "monthname":"October",
    "monthname_short":"Oct",
    "weekday_short":"Sat",
    "weekday":"Saturday",
    "ampm":"PM",
    "tz_short":"PDT",
    "tz_long":"America/Los_Angeles"
},
        "period":6,
        "high": {
        "fahrenheit":"71",
        "celsius":"22"
        },
        "low": {
        "fahrenheit":"57",
        "celsius":"14"
        },
        "conditions":"Clear",
        "icon":"clear",
        "icon_url":"http://icons.wxug.com/i/c/k/clear.gif",
        "skyicon":"",
        "pop":0,
        "qpf_allday": {
        "in": 0.00,
        "mm": 0
        },
        "qpf_day": {
        "in": 0.00,
        "mm": 0
        },
        "qpf_night": {
        "in": 0.00,
        "mm": 0
        },
        "snow_allday": {
        "in": 0.0,
        "cm": 0.0
        },
        "snow_day": {
        "in": 0.0,
        "cm": 0.0
        },
        "snow_night": {
        "in": 0.0,
        "cm": 0.0
        },
        "maxwind": {
        "mph": 15,
        "kph": 24,
        "dir": "N",
        "degrees": 0
        },
        "avewind": {
        "mph": 12,
        "kph": 19,
        "dir": "N",
        "degrees": 0
        },
        "avehumidity": 61,
        "maxhumidity": 0,
        "minhumidity": 0
        }
        ,
        {"date":{
    "epoch":"1446433200",
    "pretty":"7:00 PM PST on November 01, 2015",
    "day":1,
    "month":11,
    "year":2015,
    "yday":304,
    "hour":19,
    "min":"00",
    "sec":0,
    "isdst":"0",
    "monthname":"November",
    "monthname_short":"Nov",
    "weekday_short":"Sun",
    "weekday":"Sunday",
    "ampm":"PM",
    "tz_short":"PST",
    "tz_long":"America/Los_Angeles"
},
        "period":7,
        "high": {
        "fahrenheit":"65",
        "celsius":"18"
        },
        "low": {
        "fahrenheit":"55",
        "celsius":"13"
        },
        "conditions":"Partly Cloudy",
        "icon":"partlycloudy",
        "icon_url":"http://icons.wxug.com/i/c/k/partlycloudy.gif",
        "skyicon":"",
        "pop":10,
        "qpf_allday": {
        "in": 0.00,
        "mm": 0
        },
        "qpf_day": {
        "in": 0.00,
        "mm": 0
        },
        "qpf_night": {
        "in": 0.00,
        "mm": 0
        },
        "snow_allday": {
        "in": 0.0,
        "cm": 0.0
        },
        "snow_day": {
        "in": 0.0,
        "cm": 0.0
        },
        "snow_night": {
        "in": 0.0,
        "cm": 0.0
        },
        "maxwind": {
        "mph": 20,
        "kph": 32,
        "dir": "WNW",
        "degrees": 299
        },
        "avewind": {
        "mph": 16,
        "kph": 26,
        "dir": "WNW",
        "degrees": 299
        },
        "avehumidity": 84,
        "maxhumidity": 0,
        "minhumidity": 0
        }
        ,
        {"date":{
    "epoch":"1446519600",
    "pretty":"7:00 PM PST on November 02, 2015",
    "day":2,
    "month":11,
    "year":2015,
    "yday":305,
    "hour":19,
    "min":"00",
    "sec":0,
    "isdst":"0",
    "monthname":"November",
    "monthname_short":"Nov",
    "weekday_short":"Mon",
    "weekday":"Monday",
    "ampm":"PM",
    "tz_short":"PST",
    "tz_long":"America/Los_Angeles"
},
        "period":8,
        "high": {
        "fahrenheit":"62",
        "celsius":"17"
        },
        "low": {
        "fahrenheit":"52",
        "celsius":"11"
        },
        "conditions":"Partly Cloudy",
        "icon":"partlycloudy",
        "icon_url":"http://icons.wxug.com/i/c/k/partlycloudy.gif",
        "skyicon":"",
        "pop":10,
        "qpf_allday": {
        "in": 0.00,
        "mm": 0
        },
        "qpf_day": {
        "in": 0.00,
        "mm": 0
        },
        "qpf_night": {
        "in": 0.00,
        "mm": 0
        },
        "snow_allday": {
        "in": 0.0,
        "cm": 0.0
        },
        "snow_day": {
        "in": 0.0,
        "cm": 0.0
        },
        "snow_night": {
        "in": 0.0,
        "cm": 0.0
        },
        "maxwind": {
        "mph": 30,
        "kph": 48,
        "dir": "NW",
        "degrees": 310
        },
        "avewind": {
        "mph": 20,
        "kph": 32,
        "dir": "NW",
        "degrees": 310
        },
        "avehumidity": 69,
        "maxhumidity": 0,
        "minhumidity": 0
        }
        ,
        {"date":{
    "epoch":"1446606000",
    "pretty":"7:00 PM PST on November 03, 2015",
    "day":3,
    "month":11,
    "year":2015,
    "yday":306,
    "hour":19,
    "min":"00",
    "sec":0,
    "isdst":"0",
    "monthname":"November",
    "monthname_short":"Nov",
    "weekday_short":"Tue",
    "weekday":"Tuesday",
    "ampm":"PM",
    "tz_short":"PST",
    "tz_long":"America/Los_Angeles"
},
        "period":9,
        "high": {
        "fahrenheit":"63",
        "celsius":"17"
        },
        "low": {
        "fahrenheit":"52",
        "celsius":"11"
        },
        "conditions":"Partly Cloudy",
        "icon":"partlycloudy",
        "icon_url":"http://icons.wxug.com/i/c/k/partlycloudy.gif",
        "skyicon":"",
        "pop":0,
        "qpf_allday": {
        "in": 0.00,
        "mm": 0
        },
        "qpf_day": {
        "in": 0.00,
        "mm": 0
        },
        "qpf_night": {
        "in": 0.00,
        "mm": 0
        },
        "snow_allday": {
        "in": 0.0,
        "cm": 0.0
        },
        "snow_day": {
        "in": 0.0,
        "cm": 0.0
        },
        "snow_night": {
        "in": 0.0,
        "cm": 0.0
        },
        "maxwind": {
        "mph": 25,
        "kph": 40,
        "dir": "NW",
        "degrees": 326
        },
        "avewind": {
        "mph": 19,
        "kph": 31,
        "dir": "NW",
        "degrees": 326
        },
        "avehumidity": 58,
        "maxhumidity": 0,
        "minhumidity": 0
        }
        ,
        {"date":{
    "epoch":"1446692400",
    "pretty":"7:00 PM PST on November 04, 2015",
    "day":4,
    "month":11,
    "year":2015,
    "yday":307,
    "hour":19,
    "min":"00",
    "sec":0,
    "isdst":"0",
    "monthname":"November",
    "monthname_short":"Nov",
    "weekday_short":"Wed",
    "weekday":"Wednesday",
    "ampm":"PM",
    "tz_short":"PST",
    "tz_long":"America/Los_Angeles"
},
        "period":10,
        "high": {
        "fahrenheit":"65",
        "celsius":"18"
        },
        "low": {
        "fahrenheit":"52",
        "celsius":"11"
        },
        "conditions":"Clear",
        "icon":"clear",
        "icon_url":"http://icons.wxug.com/i/c/k/clear.gif",
        "skyicon":"",
        "pop":0,
        "qpf_allday": {
        "in": 0.00,
        "mm": 0
        },
        "qpf_day": {
        "in": 0.00,
        "mm": 0
        },
        "qpf_night": {
        "in": 0.00,
        "mm": 0
        },
        "snow_allday": {
        "in": 0.0,
        "cm": 0.0
        },
        "snow_day": {
        "in": 0.0,
        "cm": 0.0
        },
        "snow_night": {
        "in": 0.0,
        "cm": 0.0
        },
        "maxwind": {
        "mph": 20,
        "kph": 32,
        "dir": "N",
        "degrees": 357
        },
        "avewind": {
        "mph": 13,
        "kph": 21,
        "dir": "N",
        "degrees": 357
        },
        "avehumidity": 45,
        "maxhumidity": 0,
        "minhumidity": 0
        }
        ]
        }
    }
}

I need to get the all elements which are under the forecastday array. 我需要获取forecastday数组下的所有元素。

I have tried to get the required response this way: 我试图通过这种方式获得所需的响应:

  1. I have created some model classes 我创建了一些模型类

    #region For next 10 days brodcast #region接下来的10天广播

     public class forecast { public simpleforecast simpleforecast { get; set; } } public class simpleforecast { public List<item> forecastday { get; set; } } public class high { public decimal fahrenheit { get; set; } public decimal celsius { get; set; } } public class low { public decimal fahrenheit { get; set; } public decimal celsius { get; set; } } public class item { public high high { get; set; } public low low { get; set; } } #endregion 

and then tried to deserializer like this: 然后尝试像这样反序列化:

var test1 = new JsonSerializer().Deserialize(new StringReader(responseData), new forecast().GetType()) as forecast;

but no luck. 但没有运气。 Please let me know am on right path? 请让我知道正确的道路吗? or should I change my approach? 还是应该改变方法?

Any suggestion or trick or code example, article anything may help me. 任何建议,技巧或代码示例,任何文章都可能对我有所帮助。

Thanks in advance. 提前致谢。

This should be your model: 这应该是您的模型:

public class Features
{
    public int forecast10day { get; set; }
}

public class Response
{
    public string version { get; set; }
    public string termsofService { get; set; }
    public Features features { get; set; }
}

public class Forecastday
{
    public int period { get; set; }
    public string icon { get; set; }
    public string icon_url { get; set; }
    public string title { get; set; }
    public string fcttext { get; set; }
    public string fcttext_metric { get; set; }
    public string pop { get; set; }
}

public class TxtForecast
{
    public string date { get; set; }
    public List<Forecastday> forecastday { get; set; }
}

public class Date
{
    public string epoch { get; set; }
    public string pretty { get; set; }
    public int day { get; set; }
    public int month { get; set; }
    public int year { get; set; }
    public int yday { get; set; }
    public int hour { get; set; }
    public string min { get; set; }
    public int sec { get; set; }
    public string isdst { get; set; }
    public string monthname { get; set; }
    public string monthname_short { get; set; }
    public string weekday_short { get; set; }
    public string weekday { get; set; }
    public string ampm { get; set; }
    public string tz_short { get; set; }
    public string tz_long { get; set; }
}

public class High
{
    public string fahrenheit { get; set; }
    public string celsius { get; set; }
}

public class Low
{
    public string fahrenheit { get; set; }
    public string celsius { get; set; }
}

public class QpfAllday
{
    public double @in { get; set; }
    public int mm { get; set; }
}

public class QpfDay
{
    public double @in { get; set; }
    public int mm { get; set; }
}

public class QpfNight
{
    public double @in { get; set; }
    public int mm { get; set; }
}

public class SnowAllday
{
    public double @in { get; set; }
    public double cm { get; set; }
}

public class SnowDay
{
    public double @in { get; set; }
    public double cm { get; set; }
}

public class SnowNight
{
    public double @in { get; set; }
    public double cm { get; set; }
}

public class Maxwind
{
    public int mph { get; set; }
    public int kph { get; set; }
    public string dir { get; set; }
    public int degrees { get; set; }
}

public class Avewind
{
    public int mph { get; set; }
    public int kph { get; set; }
    public string dir { get; set; }
    public int degrees { get; set; }
}

public class Forecastday2
{
    public Date date { get; set; }
    public int period { get; set; }
    public High high { get; set; }
    public Low low { get; set; }
    public string conditions { get; set; }
    public string icon { get; set; }
    public string icon_url { get; set; }
    public string skyicon { get; set; }
    public int pop { get; set; }
    public QpfAllday qpf_allday { get; set; }
    public QpfDay qpf_day { get; set; }
    public QpfNight qpf_night { get; set; }
    public SnowAllday snow_allday { get; set; }
    public SnowDay snow_day { get; set; }
    public SnowNight snow_night { get; set; }
    public Maxwind maxwind { get; set; }
    public Avewind avewind { get; set; }
    public int avehumidity { get; set; }
    public int maxhumidity { get; set; }
    public int minhumidity { get; set; }
}

public class Simpleforecast
{
    public List<Forecastday2> forecastday { get; set; }
}

public class Forecast
{
    public TxtForecast txt_forecast { get; set; }
    public Simpleforecast simpleforecast { get; set; }
}

public class MainModel
{
    public Response response { get; set; }
    public Forecast forecast { get; set; }
}

Then you can do the following: 然后,您可以执行以下操作:

var test1 = new JsonSerializer().Deserialize(new StringReader(responseData), new forecast().GetType()) as forecast;
var dict = new JavaScriptSerializer().Deserialize<Dictionary<string,object>>(responseData);
var forecastdayvar = ["forecast"]["forecastday"];

This will put your JSON in a Dictionary and now you can access it's elements. 这会将您的JSON放入字典中,现在您可以访问它的元素了。 Kinda like how PHP it does with an array. Kinda喜欢PHP如何处理数组。 As you can see in: https://msdn.microsoft.com/en-us/library/xfhwa508(v=vs.110).aspx 如您所见: https : //msdn.microsoft.com/zh-cn/library/xfhwa508(v=vs.110).aspx

You might want to put a breakpoint after deserialising and look for the keys and values inside. 您可能要在反序列化之后放置一个断点,然后在其中查找键和值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM