2014-10-22 2 views
-1

Хорошо, поэтому я пытаюсь вывести некоторые данные из файла JSON из Weather Underground для приложения для Android. Мне нужна текущая температура и условия дня, в течение следующих 10 дней. Представленные данные JSON дают 10-дневный прогноз, но я понятия не имею, как разобрать каждый день отдельно. И у меня даже возникли проблемы с попыткой просто получить температуру и состояние в один вывод строки.Разбор данных JSON для Java для Android Weather App

Вот JSON набор:

{ 
 
    "response": { 
 
    "version":"0.1", 
 
    "termsofService":"http://www.wunderground.com/weather/api/d/terms.html", 
 
    "features": { 
 
    "forecast10day": 1 
 
    } 
 
\t } 
 
\t \t , 
 
\t "forecast":{ 
 
\t \t "txt_forecast": { 
 
\t \t "date":"1:27 PM CDT", 
 
\t \t "forecastday": [ 
 
\t \t { 
 
\t \t "period":0, 
 
\t \t "icon":"partlycloudy", 
 
\t \t "icon_url":"http://icons.wxug.com/i/c/k/partlycloudy.gif", 
 
\t \t "title":"Wednesday", 
 
\t \t "fcttext":"A mix of clouds and sun. Slight chance of a rain shower. High around 60F. Winds SSE at 10 to 20 mph.", 
 
\t \t "fcttext_metric":"Sun and clouds mixed. Slight chance of a rain shower. High near 15C. Winds SSE at 15 to 30 km/h.", 
 
\t \t "pop":"10" 
 
\t \t } 
 
\t \t , 
 
\t \t { 
 
\t \t "period":1, 
 
\t \t "icon":"nt_rain", 
 
\t \t "icon_url":"http://icons.wxug.com/i/c/k/nt_rain.gif", 
 
\t \t "title":"Wednesday Night", 
 
\t \t "fcttext":"Showers and thundershowers this evening will give way to steady rain overnight. Low 51F. Winds S at 10 to 15 mph. Chance of rain 70%.", 
 
\t \t "fcttext_metric":"Showers and thundershowers this evening, then cloudy with rain likely overnight. Low around 10C. Winds S at 15 to 25 km/h. Chance of rain 70%.", 
 
\t \t "pop":"70" 
 
\t \t } 
 
\t \t , 
 
\t \t { 
 
\t \t "period":2, 
 
\t \t "icon":"partlycloudy", 
 
\t \t "icon_url":"http://icons.wxug.com/i/c/k/partlycloudy.gif", 
 
\t \t "title":"Thursday", 
 
\t \t "fcttext":"Morning clouds will give way to sunshine for the afternoon. High around 70F. Winds WSW at 5 to 10 mph.", 
 
\t \t "fcttext_metric":"Morning clouds will give way to sunshine for the afternoon. High 21C. Winds WSW at 10 to 15 km/h.", 
 
\t \t "pop":"20" 
 
\t \t } 
 
\t \t , 
 
\t \t { 
 
\t \t "period":3, 
 
\t \t "icon":"nt_clear", 
 
\t \t "icon_url":"http://icons.wxug.com/i/c/k/nt_clear.gif", 
 
\t \t "title":"Thursday Night", 
 
\t \t "fcttext":"A mostly clear sky. Low around 45F. Winds light and variable.", 
 
\t \t "fcttext_metric":"Mostly clear. Low 7C. Winds light and variable.", 
 
\t \t "pop":"0" 
 
\t \t } 
 
\t \t , 
 
\t \t { 
 
\t \t "period":4, 
 
\t \t "icon":"partlycloudy", 
 
\t \t "icon_url":"http://icons.wxug.com/i/c/k/partlycloudy.gif", 
 
\t \t "title":"Friday", 
 
\t \t "fcttext":"Partly cloudy. High 71F. Winds SSW at 5 to 10 mph.", 
 
\t \t "fcttext_metric":"Intervals of clouds and sunshine. High 22C. Winds SSW at 10 to 15 km/h.", 
 
\t \t "pop":"0" 
 
\t \t } 
 
\t \t , 
 
\t \t { 
 
\t \t "period":5, 
 
\t \t "icon":"nt_partlycloudy", 
 
\t \t "icon_url":"http://icons.wxug.com/i/c/k/nt_partlycloudy.gif", 
 
\t \t "title":"Friday Night", 
 
\t \t "fcttext":"A few clouds. Low 49F. Winds W at 10 to 15 mph.", 
 
\t \t "fcttext_metric":"A few clouds. Low 9C. Winds W at 10 to 15 km/h.", 
 
\t \t "pop":"0" 
 
\t \t } 
 
\t \t , 
 
\t \t { 
 
\t \t "period":6, 
 
\t \t "icon":"clear", 
 
\t \t "icon_url":"http://icons.wxug.com/i/c/k/clear.gif", 
 
\t \t "title":"Saturday", 
 
\t \t "fcttext":"Sunny. High near 65F. Winds WNW at 10 to 20 mph.", 
 
\t \t "fcttext_metric":"Mainly sunny. High 18C. Winds WNW at 15 to 30 km/h.", 
 
\t \t "pop":"0" 
 
\t \t } 
 
\t \t , 
 
\t \t { 
 
\t \t "period":7, 
 
\t \t "icon":"nt_clear", 
 
\t \t "icon_url":"http://icons.wxug.com/i/c/k/nt_clear.gif", 
 
\t \t "title":"Saturday Night", 
 
\t \t "fcttext":"A mostly clear sky. Low 42F. Winds WNW at 5 to 10 mph.", 
 
\t \t "fcttext_metric":"Clear skies. Low 6C. Winds WNW at 10 to 15 km/h.", 
 
\t \t "pop":"0" 
 
\t \t } 
 
\t \t , 
 
\t \t { 
 
\t \t "period":8, 
 
\t \t "icon":"clear", 
 
\t \t "icon_url":"http://icons.wxug.com/i/c/k/clear.gif", 
 
\t \t "title":"Sunday", 
 
\t \t "fcttext":"Mostly sunny skies. High 63F. Winds SE at 10 to 15 mph.", 
 
\t \t "fcttext_metric":"Generally sunny despite a few afternoon clouds. High 17C. Winds SE at 15 to 25 km/h.", 
 
\t \t "pop":"10" 
 
\t \t } 
 
\t \t , 
 
\t \t { 
 
\t \t "period":9, 
 
\t \t "icon":"nt_chancerain", 
 
\t \t "icon_url":"http://icons.wxug.com/i/c/k/nt_chancerain.gif", 
 
\t \t "title":"Sunday Night", 
 
\t \t "fcttext":"Partly cloudy skies early followed by increasing clouds with showers developing later at night. Low 51F. Winds SE at 10 to 15 mph. Chance of rain 40%.", 
 
\t \t "fcttext_metric":"Partly cloudy skies early followed by increasing clouds with showers developing later at night. Low around 10C. Winds SE at 10 to 15 km/h. Chance of rain 40%.", 
 
\t \t "pop":"40" 
 
\t \t } 
 
\t \t , 
 
\t \t { 
 
\t \t "period":10, 
 
\t \t "icon":"chancerain", 
 
\t \t "icon_url":"http://icons.wxug.com/i/c/k/chancerain.gif", 
 
\t \t "title":"Monday", 
 
\t \t "fcttext":"Showers early becoming less numerous later in the day. High 62F. Winds WSW at 5 to 10 mph. Chance of rain 40%.", 
 
\t \t "fcttext_metric":"Chance of a shower or two during the morning, followed by partly cloudy skies in the afternoon. High 17C. Winds WSW at 10 to 15 km/h. Chance of rain 30%.", 
 
\t \t "pop":"40" 
 
\t \t } 
 
\t \t , 
 
\t \t { 
 
\t \t "period":11, 
 
\t \t "icon":"nt_chancerain", 
 
\t \t "icon_url":"http://icons.wxug.com/i/c/k/nt_chancerain.gif", 
 
\t \t "title":"Monday Night", 
 
\t \t "fcttext":"A shower or two around the area in the evening, then partly cloudy overnight. Low 47F. Winds WNW at 10 to 15 mph. Chance of rain 30%.", 
 
\t \t "fcttext_metric":"A few clouds. Low 8C. Winds WNW at 15 to 25 km/h.", 
 
\t \t "pop":"30" 
 
\t \t } 
 
\t \t , 
 
\t \t { 
 
\t \t "period":12, 
 
\t \t "icon":"mostlycloudy", 
 
\t \t "icon_url":"http://icons.wxug.com/i/c/k/mostlycloudy.gif", 
 
\t \t "title":"Tuesday", 
 
\t \t "fcttext":"Partly cloudy skies during the morning hours will become overcast in the afternoon. High 52F. Winds WNW at 15 to 25 mph.", 
 
\t \t "fcttext_metric":"Partly to mostly cloudy. High 11C. Winds WNW at 25 to 40 km/h.", 
 
\t \t "pop":"10" 
 
\t \t } 
 
\t \t , 
 
\t \t { 
 
\t \t "period":13, 
 
\t \t "icon":"nt_clear", 
 
\t \t "icon_url":"http://icons.wxug.com/i/c/k/nt_clear.gif", 
 
\t \t "title":"Tuesday Night", 
 
\t \t "fcttext":"A mostly clear sky. Low 37F. Winds W at 5 to 10 mph.", 
 
\t \t "fcttext_metric":"A mostly clear sky. Low 3C. Winds W at 10 to 15 km/h.", 
 
\t \t "pop":"10" 
 
\t \t } 
 
\t \t , 
 
\t \t { 
 
\t \t "period":14, 
 
\t \t "icon":"clear", 
 
\t \t "icon_url":"http://icons.wxug.com/i/c/k/clear.gif", 
 
\t \t "title":"Wednesday", 
 
\t \t "fcttext":"Generally sunny despite a few afternoon clouds. High 53F. Winds WSW at 5 to 10 mph.", 
 
\t \t "fcttext_metric":"Generally sunny despite a few afternoon clouds. High 12C. Winds WSW at 10 to 15 km/h.", 
 
\t \t "pop":"10" 
 
\t \t } 
 
\t \t , 
 
\t \t { 
 
\t \t "period":15, 
 
\t \t "icon":"nt_partlycloudy", 
 
\t \t "icon_url":"http://icons.wxug.com/i/c/k/nt_partlycloudy.gif", 
 
\t \t "title":"Wednesday Night", 
 
\t \t "fcttext":"Partly cloudy skies. Low 37F. Winds W at 5 to 10 mph.", 
 
\t \t "fcttext_metric":"A few clouds. Low 3C. Winds W at 10 to 15 km/h.", 
 
\t \t "pop":"20" 
 
\t \t } 
 
\t \t , 
 
\t \t { 
 
\t \t "period":16, 
 
\t \t "icon":"partlycloudy", 
 
\t \t "icon_url":"http://icons.wxug.com/i/c/k/partlycloudy.gif", 
 
\t \t "title":"Thursday", 
 
\t \t "fcttext":"Intervals of clouds and sunshine. High 52F. Winds NNW at 5 to 10 mph.", 
 
\t \t "fcttext_metric":"Partly cloudy skies. High 11C. Winds NNW at 10 to 15 km/h.", 
 
\t \t "pop":"20" 
 
\t \t } 
 
\t \t , 
 
\t \t { 
 
\t \t "period":17, 
 
\t \t "icon":"nt_clear", 
 
\t \t "icon_url":"http://icons.wxug.com/i/c/k/nt_clear.gif", 
 
\t \t "title":"Thursday Night", 
 
\t \t "fcttext":"A few clouds from time to time. Low 37F. Winds NNW at 5 to 10 mph.", 
 
\t \t "fcttext_metric":"Mostly clear skies. Low 3C. Winds NNW at 10 to 15 km/h.", 
 
\t \t "pop":"20" 
 
\t \t } 
 
\t \t , 
 
\t \t { 
 
\t \t "period":18, 
 
\t \t "icon":"clear", 
 
\t \t "icon_url":"http://icons.wxug.com/i/c/k/clear.gif", 
 
\t \t "title":"Friday", 
 
\t \t "fcttext":"Except for a few afternoon clouds, mainly sunny. High 48F. Winds NE at 5 to 10 mph.", 
 
\t \t "fcttext_metric":"Generally sunny despite a few afternoon clouds. High 9C. Winds NE at 10 to 15 km/h.", 
 
\t \t "pop":"10" 
 
\t \t } 
 
\t \t , 
 
\t \t { 
 
\t \t "period":19, 
 
\t \t "icon":"nt_partlycloudy", 
 
\t \t "icon_url":"http://icons.wxug.com/i/c/k/nt_partlycloudy.gif", 
 
\t \t "title":"Friday Night", 
 
\t \t "fcttext":"A few clouds from time to time. Low 36F. Winds SE at 5 to 10 mph.", 
 
\t \t "fcttext_metric":"Partly cloudy skies. Low 2C. Winds SE at 10 to 15 km/h.", 
 
\t \t "pop":"10" 
 
\t \t } 
 
\t \t ] 
 
\t \t }, 
 
\t \t "simpleforecast": { 
 
\t \t "forecastday": [ 
 
\t \t {"date":{ 
 
\t "epoch":"1414022400", 
 
\t "pretty":"7:00 PM CDT on October 22, 2014", 
 
\t "day":22, 
 
\t "month":10, 
 
\t "year":2014, 
 
\t "yday":294, 
 
\t "hour":19, 
 
\t "min":"00", 
 
\t "sec":0, 
 
\t "isdst":"1", 
 
\t "monthname":"October", 
 
\t "monthname_short":"Oct", 
 
\t "weekday_short":"Wed", 
 
\t "weekday":"Wednesday", 
 
\t "ampm":"PM", 
 
\t "tz_short":"CDT", 
 
\t "tz_long":"America/Chicago" 
 
}, 
 
\t \t "period":1, 
 
\t \t "high": { 
 
\t \t "fahrenheit":"60", 
 
\t \t "celsius":"16" 
 
\t \t }, 
 
\t \t "low": { 
 
\t \t "fahrenheit":"51", 
 
\t \t "celsius":"11" 
 
\t \t }, 
 
\t \t "conditions":"Partly Cloudy", 
 
\t \t "icon":"partlycloudy", 
 
\t \t "icon_url":"http://icons.wxug.com/i/c/k/partlycloudy.gif", 
 
\t \t "skyicon":"", 
 
\t \t "pop":10, 
 
\t \t "qpf_allday": { 
 
\t \t "in": 0.19, 
 
\t \t "mm": 5 
 
\t \t }, 
 
\t \t "qpf_day": { 
 
\t \t "in": 0.00, 
 
\t \t "mm": 0 
 
\t \t }, 
 
\t \t "qpf_night": { 
 
\t \t "in": 0.19, 
 
\t \t "mm": 5 
 
\t \t }, 
 
\t \t "snow_allday": { 
 
\t \t "in": 0.0, 
 
\t \t "cm": 0.0 
 
\t \t }, 
 
\t \t "snow_day": { 
 
\t \t "in": 0.0, 
 
\t \t "cm": 0.0 
 
\t \t }, 
 
\t \t "snow_night": { 
 
\t \t "in": 0.0, 
 
\t \t "cm": 0.0 
 
\t \t }, 
 
\t \t "maxwind": { 
 
\t \t "mph": 20, 
 
\t \t "kph": 32, 
 
\t \t "dir": "SSE", 
 
\t \t "degrees": 151 
 
\t \t }, 
 
\t \t "avewind": { 
 
\t \t "mph": 15, 
 
\t \t "kph": 24, 
 
\t \t "dir": "SSE", 
 
\t \t "degrees": 151 
 
\t \t }, 
 
\t \t "avehumidity": 56, 
 
\t \t "maxhumidity": 0, 
 
\t \t "minhumidity": 0 
 
\t \t } 
 
\t \t , 
 
\t \t {"date":{ 
 
\t "epoch":"1414108800", 
 
\t "pretty":"7:00 PM CDT on October 23, 2014", 
 
\t "day":23, 
 
\t "month":10, 
 
\t "year":2014, 
 
\t "yday":295, 
 
\t "hour":19, 
 
\t "min":"00", 
 
\t "sec":0, 
 
\t "isdst":"1", 
 
\t "monthname":"October", 
 
\t "monthname_short":"Oct", 
 
\t "weekday_short":"Thu", 
 
\t "weekday":"Thursday", 
 
\t "ampm":"PM", 
 
\t "tz_short":"CDT", 
 
\t "tz_long":"America/Chicago" 
 
}, 
 
\t \t "period":2, 
 
\t \t "high": { 
 
\t \t "fahrenheit":"70", 
 
\t \t "celsius":"21" 
 
\t \t }, 
 
\t \t "low": { 
 
\t \t "fahrenheit":"45", 
 
\t \t "celsius":"7" 
 
\t \t }, 
 
\t \t "conditions":"Partly Cloudy", 
 
\t \t "icon":"partlycloudy", 
 
\t \t "icon_url":"http://icons.wxug.com/i/c/k/partlycloudy.gif", 
 
\t \t "skyicon":"", 
 
\t \t "pop":20, 
 
\t \t "qpf_allday": { 
 
\t \t "in": 0.00, 
 
\t \t "mm": 0 
 
\t \t }, 
 
\t \t "qpf_day": { 
 
\t \t "in": 0.00, 
 
\t \t "mm": 0 
 
\t \t }, 
 
\t \t "qpf_night": { 
 
\t \t "in": 0.00, 
 
\t \t "mm": 0 
 
\t \t }, 
 
\t \t "snow_allday": { 
 
\t \t "in": 0.0, 
 
\t \t "cm": 0.0 
 
\t \t }, 
 
\t \t "snow_day": { 
 
\t \t "in": 0.0, 
 
\t \t "cm": 0.0 
 
\t \t }, 
 
\t \t "snow_night": { 
 
\t \t "in": 0.0, 
 
\t \t "cm": 0.0 
 
\t \t }, 
 
\t \t "maxwind": { 
 
\t \t "mph": 10, 
 
\t \t "kph": 16, 
 
\t \t "dir": "WSW", 
 
\t \t "degrees": 246 
 
\t \t }, 
 
\t \t "avewind": { 
 
\t \t "mph": 7, 
 
\t \t "kph": 11, 
 
\t \t "dir": "WSW", 
 
\t \t "degrees": 246 
 
\t \t }, 
 
\t \t "avehumidity": 69, 
 
\t \t "maxhumidity": 0, 
 
\t \t "minhumidity": 0 
 
\t \t } 
 
\t \t , 
 
\t \t {"date":{ 
 
\t "epoch":"1414195200", 
 
\t "pretty":"7:00 PM CDT on October 24, 2014", 
 
\t "day":24, 
 
\t "month":10, 
 
\t "year":2014, 
 
\t "yday":296, 
 
\t "hour":19, 
 
\t "min":"00", 
 
\t "sec":0, 
 
\t "isdst":"1", 
 
\t "monthname":"October", 
 
\t "monthname_short":"Oct", 
 
\t "weekday_short":"Fri", 
 
\t "weekday":"Friday", 
 
\t "ampm":"PM", 
 
\t "tz_short":"CDT", 
 
\t "tz_long":"America/Chicago" 
 
}, 
 
\t \t "period":3, 
 
\t \t "high": { 
 
\t \t "fahrenheit":"71", 
 
\t \t "celsius":"22" 
 
\t \t }, 
 
\t \t "low": { 
 
\t \t "fahrenheit":"49", 
 
\t \t "celsius":"9" 
 
\t \t }, 
 
\t \t "conditions":"Partly Cloudy", 
 
\t \t "icon":"partlycloudy", 
 
\t \t "icon_url":"http://icons.wxug.com/i/c/k/partlycloudy.gif", 
 
\t \t "skyicon":"", 
 
\t \t "pop":0, 
 
\t \t "qpf_allday": { 
 
\t \t "in": 0.00, 
 
\t \t "mm": 0 
 
\t \t }, 
 
\t \t "qpf_day": { 
 
\t \t "in": 0.00, 
 
\t \t "mm": 0 
 
\t \t }, 
 
\t \t "qpf_night": { 
 
\t \t "in": 0.00, 
 
\t \t "mm": 0 
 
\t \t }, 
 
\t \t "snow_allday": { 
 
\t \t "in": 0.0, 
 
\t \t "cm": 0.0 
 
\t \t }, 
 
\t \t "snow_day": { 
 
\t \t "in": 0.0, 
 
\t \t "cm": 0.0 
 
\t \t }, 
 
\t \t "snow_night": { 
 
\t \t "in": 0.0, 
 
\t \t "cm": 0.0 
 
\t \t }, 
 
\t \t "maxwind": { 
 
\t \t "mph": 10, 
 
\t \t "kph": 16, 
 
\t \t "dir": "SSW", 
 
\t \t "degrees": 209 
 
\t \t }, 
 
\t \t "avewind": { 
 
\t \t "mph": 8, 
 
\t \t "kph": 13, 
 
\t \t "dir": "SSW", 
 
\t \t "degrees": 209 
 
\t \t }, 
 
\t \t "avehumidity": 64, 
 
\t \t "maxhumidity": 0, 
 
\t \t "minhumidity": 0 
 
\t \t } 
 
\t \t , 
 
\t \t {"date":{ 
 
\t "epoch":"1414281600", 
 
\t "pretty":"7:00 PM CDT on October 25, 2014", 
 
\t "day":25, 
 
\t "month":10, 
 
\t "year":2014, 
 
\t "yday":297, 
 
\t "hour":19, 
 
\t "min":"00", 
 
\t "sec":0, 
 
\t "isdst":"1", 
 
\t "monthname":"October", 
 
\t "monthname_short":"Oct", 
 
\t "weekday_short":"Sat", 
 
\t "weekday":"Saturday", 
 
\t "ampm":"PM", 
 
\t "tz_short":"CDT", 
 
\t "tz_long":"America/Chicago" 
 
}, 
 
\t \t "period":4, 
 
\t \t "high": { 
 
\t \t "fahrenheit":"65", 
 
\t \t "celsius":"18" 
 
\t \t }, 
 
\t \t "low": { 
 
\t \t "fahrenheit":"42", 
 
\t \t "celsius":"6" 
 
\t \t }, 
 
\t \t "conditions":"Clear", 
 
\t \t "icon":"clear", 
 
\t \t "icon_url":"http://icons.wxug.com/i/c/k/clear.gif", 
 
\t \t "skyicon":"", 
 
\t \t "pop":0, 
 
\t \t "qpf_allday": { 
 
\t \t "in": 0.00, 
 
\t \t "mm": 0 
 
\t \t }, 
 
\t \t "qpf_day": { 
 
\t \t "in": 0.00, 
 
\t \t "mm": 0 
 
\t \t }, 
 
\t \t "qpf_night": { 
 
\t \t "in": 0.00, 
 
\t \t "mm": 0 
 
\t \t }, 
 
\t \t "snow_allday": { 
 
\t \t "in": 0.0, 
 
\t \t "cm": 0.0 
 
\t \t }, 
 
\t \t "snow_day": { 
 
\t \t "in": 0.0, 
 
\t \t "cm": 0.0 
 
\t \t }, 
 
\t \t "snow_night": { 
 
\t \t "in": 0.0, 
 
\t \t "cm": 0.0 
 
\t \t }, 
 
\t \t "maxwind": { 
 
\t \t "mph": 20, 
 
\t \t "kph": 32, 
 
\t \t "dir": "WNW", 
 
\t \t "degrees": 298 
 
\t \t }, 
 
\t \t "avewind": { 
 
\t \t "mph": 16, 
 
\t \t "kph": 26, 
 
\t \t "dir": "WNW", 
 
\t \t "degrees": 298 
 
\t \t }, 
 
\t \t "avehumidity": 42, 
 
\t \t "maxhumidity": 0, 
 
\t \t "minhumidity": 0 
 
\t \t } 
 
\t \t , 
 
\t \t {"date":{ 
 
\t "epoch":"1414368000", 
 
\t "pretty":"7:00 PM CDT on October 26, 2014", 
 
\t "day":26, 
 
\t "month":10, 
 
\t "year":2014, 
 
\t "yday":298, 
 
\t "hour":19, 
 
\t "min":"00", 
 
\t "sec":0, 
 
\t "isdst":"1", 
 
\t "monthname":"October", 
 
\t "monthname_short":"Oct", 
 
\t "weekday_short":"Sun", 
 
\t "weekday":"Sunday", 
 
\t "ampm":"PM", 
 
\t "tz_short":"CDT", 
 
\t "tz_long":"America/Chicago" 
 
}, 
 
\t \t "period":5, 
 
\t \t "high": { 
 
\t \t "fahrenheit":"63", 
 
\t \t "celsius":"17" 
 
\t \t }, 
 
\t \t "low": { 
 
\t \t "fahrenheit":"51", 
 
\t \t "celsius":"11" 
 
\t \t }, 
 
\t \t "conditions":"Clear", 
 
\t \t "icon":"clear", 
 
\t \t "icon_url":"http://icons.wxug.com/i/c/k/clear.gif", 
 
\t \t "skyicon":"", 
 
\t \t "pop":10, 
 
\t \t "qpf_allday": { 
 
\t \t "in": 0.03, 
 
\t \t "mm": 1 
 
\t \t }, 
 
\t \t "qpf_day": { 
 
\t \t "in": 0.00, 
 
\t \t "mm": 0 
 
\t \t }, 
 
\t \t "qpf_night": { 
 
\t \t "in": 0.03, 
 
\t \t "mm": 1 
 
\t \t }, 
 
\t \t "snow_allday": { 
 
\t \t "in": 0.0, 
 
\t \t "cm": 0.0 
 
\t \t }, 
 
\t \t "snow_day": { 
 
\t \t "in": 0.0, 
 
\t \t "cm": 0.0 
 
\t \t }, 
 
\t \t "snow_night": { 
 
\t \t "in": 0.0, 
 
\t \t "cm": 0.0 
 
\t \t }, 
 
\t \t "maxwind": { 
 
\t \t "mph": 15, 
 
\t \t "kph": 24, 
 
\t \t "dir": "SE", 
 
\t \t "degrees": 129 
 
\t \t }, 
 
\t \t "avewind": { 
 
\t \t "mph": 10, 
 
\t \t "kph": 16, 
 
\t \t "dir": "SE", 
 
\t \t "degrees": 129 
 
\t \t }, 
 
\t \t "avehumidity": 50, 
 
\t \t "maxhumidity": 0, 
 
\t \t "minhumidity": 0 
 
\t \t } 
 
\t \t , 
 
\t \t {"date":{ 
 
\t "epoch":"1414454400", 
 
\t "pretty":"7:00 PM CDT on October 27, 2014", 
 
\t "day":27, 
 
\t "month":10, 
 
\t "year":2014, 
 
\t "yday":299, 
 
\t "hour":19, 
 
\t "min":"00", 
 
\t "sec":0, 
 
\t "isdst":"1", 
 
\t "monthname":"October", 
 
\t "monthname_short":"Oct", 
 
\t "weekday_short":"Mon", 
 
\t "weekday":"Monday", 
 
\t "ampm":"PM", 
 
\t "tz_short":"CDT", 
 
\t "tz_long":"America/Chicago" 
 
}, 
 
\t \t "period":6, 
 
\t \t "high": { 
 
\t \t "fahrenheit":"62", 
 
\t \t "celsius":"17" 
 
\t \t }, 
 
\t \t "low": { 
 
\t \t "fahrenheit":"47", 
 
\t \t "celsius":"8" 
 
\t \t }, 
 
\t \t "conditions":"Chance of Rain", 
 
\t \t "icon":"chancerain", 
 
\t \t "icon_url":"http://icons.wxug.com/i/c/k/chancerain.gif", 
 
\t \t "skyicon":"", 
 
\t \t "pop":40, 
 
\t \t "qpf_allday": { 
 
\t \t "in": 0.03, 
 
\t \t "mm": 1 
 
\t \t }, 
 
\t \t "qpf_day": { 
 
\t \t "in": 0.03, 
 
\t \t "mm": 1 
 
\t \t }, 
 
\t \t "qpf_night": { 
 
\t \t "in": 0.00, 
 
\t \t "mm": 0 
 
\t \t }, 
 
\t \t "snow_allday": { 
 
\t \t "in": 0.0, 
 
\t \t "cm": 0.0 
 
\t \t }, 
 
\t \t "snow_day": { 
 
\t \t "in": 0.0, 
 
\t \t "cm": 0.0 
 
\t \t }, 
 
\t \t "snow_night": { 
 
\t \t "in": 0.0, 
 
\t \t "cm": 0.0 
 
\t \t }, 
 
\t \t "maxwind": { 
 
\t \t "mph": 10, 
 
\t \t "kph": 16, 
 
\t \t "dir": "WSW", 
 
\t \t "degrees": 237 
 
\t \t }, 
 
\t \t "avewind": { 
 
\t \t "mph": 8, 
 
\t \t "kph": 13, 
 
\t \t "dir": "WSW", 
 
\t \t "degrees": 237 
 
\t \t }, 
 
\t \t "avehumidity": 75, 
 
\t \t "maxhumidity": 0, 
 
\t \t "minhumidity": 0 
 
\t \t } 
 
\t \t , 
 
\t \t {"date":{ 
 
\t "epoch":"1414540800", 
 
\t "pretty":"7:00 PM CDT on October 28, 2014", 
 
\t "day":28, 
 
\t "month":10, 
 
\t "year":2014, 
 
\t "yday":300, 
 
\t "hour":19, 
 
\t "min":"00", 
 
\t "sec":0, 
 
\t "isdst":"1", 
 
\t "monthname":"October", 
 
\t "monthname_short":"Oct", 
 
\t "weekday_short":"Tue", 
 
\t "weekday":"Tuesday", 
 
\t "ampm":"PM", 
 
\t "tz_short":"CDT", 
 
\t "tz_long":"America/Chicago" 
 
}, 
 
\t \t "period":7, 
 
\t \t "high": { 
 
\t \t "fahrenheit":"52", 
 
\t \t "celsius":"11" 
 
\t \t }, 
 
\t \t "low": { 
 
\t \t "fahrenheit":"37", 
 
\t \t "celsius":"3" 
 
\t \t }, 
 
\t \t "conditions":"Mostly Cloudy", 
 
\t \t "icon":"mostlycloudy", 
 
\t \t "icon_url":"http://icons.wxug.com/i/c/k/mostlycloudy.gif", 
 
\t \t "skyicon":"", 
 
\t \t "pop":10, 
 
\t \t "qpf_allday": { 
 
\t \t "in": 0.00, 
 
\t \t "mm": 0 
 
\t \t }, 
 
\t \t "qpf_day": { 
 
\t \t "in": 0.00, 
 
\t \t "mm": 0 
 
\t \t }, 
 
\t \t "qpf_night": { 
 
\t \t "in": 0.00, 
 
\t \t "mm": 0 
 
\t \t }, 
 
\t \t "snow_allday": { 
 
\t \t "in": 0.0, 
 
\t \t "cm": 0.0 
 
\t \t }, 
 
\t \t "snow_day": { 
 
\t \t "in": 0.0, 
 
\t \t "cm": 0.0 
 
\t \t }, 
 
\t \t "snow_night": { 
 
\t \t "in": 0.0, 
 
\t \t "cm": 0.0 
 
\t \t }, 
 
\t \t "maxwind": { 
 
\t \t "mph": 25, 
 
\t \t "kph": 40, 
 
\t \t "dir": "WNW", 
 
\t \t "degrees": 301 
 
\t \t }, 
 
\t \t "avewind": { 
 
\t \t "mph": 18, 
 
\t \t "kph": 29, 
 
\t \t "dir": "WNW", 
 
\t \t "degrees": 301 
 
\t \t }, 
 
\t \t "avehumidity": 54, 
 
\t \t "maxhumidity": 0, 
 
\t \t "minhumidity": 0 
 
\t \t } 
 
\t \t , 
 
\t \t {"date":{ 
 
\t "epoch":"1414627200", 
 
\t "pretty":"7:00 PM CDT on October 29, 2014", 
 
\t "day":29, 
 
\t "month":10, 
 
\t "year":2014, 
 
\t "yday":301, 
 
\t "hour":19, 
 
\t "min":"00", 
 
\t "sec":0, 
 
\t "isdst":"1", 
 
\t "monthname":"October", 
 
\t "monthname_short":"Oct", 
 
\t "weekday_short":"Wed", 
 
\t "weekday":"Wednesday", 
 
\t "ampm":"PM", 
 
\t "tz_short":"CDT", 
 
\t "tz_long":"America/Chicago" 
 
}, 
 
\t \t "period":8, 
 
\t \t "high": { 
 
\t \t "fahrenheit":"53", 
 
\t \t "celsius":"12" 
 
\t \t }, 
 
\t \t "low": { 
 
\t \t "fahrenheit":"37", 
 
\t \t "celsius":"3" 
 
\t \t }, 
 
\t \t "conditions":"Clear", 
 
\t \t "icon":"clear", 
 
\t \t "icon_url":"http://icons.wxug.com/i/c/k/clear.gif", 
 
\t \t "skyicon":"", 
 
\t \t "pop":10, 
 
\t \t "qpf_allday": { 
 
\t \t "in": 0.00, 
 
\t \t "mm": 0 
 
\t \t }, 
 
\t \t "qpf_day": { 
 
\t \t "in": 0.00, 
 
\t \t "mm": 0 
 
\t \t }, 
 
\t \t "qpf_night": { 
 
\t \t "in": 0.00, 
 
\t \t "mm": 0 
 
\t \t }, 
 
\t \t "snow_allday": { 
 
\t \t "in": 0.0, 
 
\t \t "cm": 0.0 
 
\t \t }, 
 
\t \t "snow_day": { 
 
\t \t "in": 0.0, 
 
\t \t "cm": 0.0 
 
\t \t }, 
 
\t \t "snow_night": { 
 
\t \t "in": 0.0, 
 
\t \t "cm": 0.0 
 
\t \t }, 
 
\t \t "maxwind": { 
 
\t \t "mph": 10, 
 
\t \t "kph": 16, 
 
\t \t "dir": "WSW", 
 
\t \t "degrees": 239 
 
\t \t }, 
 
\t \t "avewind": { 
 
\t \t "mph": 9, 
 
\t \t "kph": 14, 
 
\t \t "dir": "WSW", 
 
\t \t "degrees": 239 
 
\t \t }, 
 
\t \t "avehumidity": 57, 
 
\t \t "maxhumidity": 0, 
 
\t \t "minhumidity": 0 
 
\t \t } 
 
\t \t , 
 
\t \t {"date":{ 
 
\t "epoch":"1414713600", 
 
\t "pretty":"7:00 PM CDT on October 30, 2014", 
 
\t "day":30, 
 
\t "month":10, 
 
\t "year":2014, 
 
\t "yday":302, 
 
\t "hour":19, 
 
\t "min":"00", 
 
\t "sec":0, 
 
\t "isdst":"1", 
 
\t "monthname":"October", 
 
\t "monthname_short":"Oct", 
 
\t "weekday_short":"Thu", 
 
\t "weekday":"Thursday", 
 
\t "ampm":"PM", 
 
\t "tz_short":"CDT", 
 
\t "tz_long":"America/Chicago" 
 
}, 
 
\t \t "period":9, 
 
\t \t "high": { 
 
\t \t "fahrenheit":"52", 
 
\t \t "celsius":"11" 
 
\t \t }, 
 
\t \t "low": { 
 
\t \t "fahrenheit":"37", 
 
\t \t "celsius":"3" 
 
\t \t }, 
 
\t \t "conditions":"Partly Cloudy", 
 
\t \t "icon":"partlycloudy", 
 
\t \t "icon_url":"http://icons.wxug.com/i/c/k/partlycloudy.gif", 
 
\t \t "skyicon":"", 
 
\t \t "pop":20, 
 
\t \t "qpf_allday": { 
 
\t \t "in": 0.00, 
 
\t \t "mm": 0 
 
\t \t }, 
 
\t \t "qpf_day": { 
 
\t \t "in": 0.00, 
 
\t \t "mm": 0 
 
\t \t }, 
 
\t \t "qpf_night": { 
 
\t \t "in": 0.00, 
 
\t \t "mm": 0 
 
\t \t }, 
 
\t \t "snow_allday": { 
 
\t \t "in": 0.0, 
 
\t \t "cm": 0.0 
 
\t \t }, 
 
\t \t "snow_day": { 
 
\t \t "in": 0.0, 
 
\t \t "cm": 0.0 
 
\t \t }, 
 
\t \t "snow_night": { 
 
\t \t "in": 0.0, 
 
\t \t "cm": 0.0 
 
\t \t }, 
 
\t \t "maxwind": { 
 
\t \t "mph": 10, 
 
\t \t "kph": 16, 
 
\t \t "dir": "NNW", 
 
\t \t "degrees": 340 
 
\t \t }, 
 
\t \t "avewind": { 
 
\t \t "mph": 9, 
 
\t \t "kph": 14, 
 
\t \t "dir": "NNW", 
 
\t \t "degrees": 340 
 
\t \t }, 
 
\t \t "avehumidity": 69, 
 
\t \t "maxhumidity": 0, 
 
\t \t "minhumidity": 0 
 
\t \t } 
 
\t \t , 
 
\t \t {"date":{ 
 
\t "epoch":"1414800000", 
 
\t "pretty":"7:00 PM CDT on October 31, 2014", 
 
\t "day":31, 
 
\t "month":10, 
 
\t "year":2014, 
 
\t "yday":303, 
 
\t "hour":19, 
 
\t "min":"00", 
 
\t "sec":0, 
 
\t "isdst":"1", 
 
\t "monthname":"October", 
 
\t "monthname_short":"Oct", 
 
\t "weekday_short":"Fri", 
 
\t "weekday":"Friday", 
 
\t "ampm":"PM", 
 
\t "tz_short":"CDT", 
 
\t "tz_long":"America/Chicago" 
 
}, 
 
\t \t "period":10, 
 
\t \t "high": { 
 
\t \t "fahrenheit":"48", 
 
\t \t "celsius":"9" 
 
\t \t }, 
 
\t \t "low": { 
 
\t \t "fahrenheit":"36", 
 
\t \t "celsius":"2" 
 
\t \t }, 
 
\t \t "conditions":"Clear", 
 
\t \t "icon":"clear", 
 
\t \t "icon_url":"http://icons.wxug.com/i/c/k/clear.gif", 
 
\t \t "skyicon":"", 
 
\t \t "pop":10, 
 
\t \t "qpf_allday": { 
 
\t \t "in": 0.00, 
 
\t \t "mm": 0 
 
\t \t }, 
 
\t \t "qpf_day": { 
 
\t \t "in": 0.00, 
 
\t \t "mm": 0 
 
\t \t }, 
 
\t \t "qpf_night": { 
 
\t \t "in": 0.00, 
 
\t \t "mm": 0 
 
\t \t }, 
 
\t \t "snow_allday": { 
 
\t \t "in": 0.0, 
 
\t \t "cm": 0.0 
 
\t \t }, 
 
\t \t "snow_day": { 
 
\t \t "in": 0.0, 
 
\t \t "cm": 0.0 
 
\t \t }, 
 
\t \t "snow_night": { 
 
\t \t "in": 0.0, 
 
\t \t "cm": 0.0 
 
\t \t }, 
 
\t \t "maxwind": { 
 
\t \t "mph": 10, 
 
\t \t "kph": 16, 
 
\t \t "dir": "NE", 
 
\t \t "degrees": 43 
 
\t \t }, 
 
\t \t "avewind": { 
 
\t \t "mph": 8, 
 
\t \t "kph": 13, 
 
\t \t "dir": "NE", 
 
\t \t "degrees": 43 
 
\t \t }, 
 
\t \t "avehumidity": 66, 
 
\t \t "maxhumidity": 0, 
 
\t \t "minhumidity": 0 
 
\t \t } 
 
\t \t ] 
 
\t \t } 
 
\t } 
 
}

И вот мой код до сих пор (для первого фрагмента день)

class RequestCurrentMplsWeatherTask extends AsyncTask<String, String, String>{ 
 
\t  \t 
 
\t  \t @Override 
 
\t  \t protected String doInBackground(String... uri) 
 
\t  \t { 
 
\t  \t String responseString = null; 
 
\t  \t try { 
 
\t  \t \t HttpClient client = new DefaultHttpClient(); 
 
\t  \t \t URI apiCall = new URI("http://api.wunderground.com/api/MYID/forecast10day/q/MN/Minneapolis.json"); 
 
\t  \t \t HttpGet request = new HttpGet(); 
 
\t  \t \t request.setURI(apiCall); 
 
\t  \t \t HttpResponse response = client.execute(request); 
 
\t  \t \t responseString = EntityUtils.toString(response.getEntity()); 
 
\t  \t } catch (Exception e) { 
 
\t  \t Log.e(TAG, "some sort of problem encountered", e); 
 
\t  \t } 
 
\t  \t return responseString; 
 
\t  \t } 
 
\t  \t 
 
\t  \t @Override 
 
\t  \t protected void onPostExecute(String result) { 
 
\t  \t super.onPostExecute(result); 
 
\t  \t if (result != null){ 
 
\t  \t Log.i(TAG, "result data was \n" + result); 
 
\t  \t try { 
 
\t  \t JSONObject jsonWeather = new JSONObject(result); 
 
\t  \t JSONObject weatherForecast = jsonWeather.getJSONObject("forecast"); 
 
\t  \t JSONObject simpleForecast = weatherForecast.getJSONObject("simpleforecast"); 
 
\t \t \t JSONArray forecastArray = simpleForecast.getJSONArray("forecastday"); 
 
\t \t \t for (int i = 0; i < forecastArray.length(); i++) { 
 
\t \t \t  JSONObject fa = forecastArray.getJSONObject(i); 
 
\t \t \t  JSONArray highArray = fa.getJSONArray("high"); 
 
\t \t \t  for (int h = 0; h < highArray.length(); h++) { 
 
\t \t \t  \t JSONObject ha = highArray.getJSONObject(h); 
 
\t \t \t  \t JSONObject fahrenheit = ha.getJSONObject("fahrenheit"); 
 
\t \t \t  \t TextView output1 = (TextView)findViewById(R.id.today_temp); 
 
\t \t \t \t  output1.setText("" + fahrenheit); 
 
\t \t \t \t  break; 
 
\t \t \t  } 
 
\t \t \t  JSONObject conditions = fa.getJSONObject("conditions"); 
 
\t \t \t  //JSONObject conditionsArray = fa.getJSONObject("conditions"); 
 
\t \t \t  TextView output2 = (TextView)findViewById(R.id.fctext); 
 
\t \t \t  output2.setText("" + conditions); 
 
\t \t \t  break; 
 
\t \t \t } 
 
\t \t \t 
 
\t  \t //String forecastArrayResult = weatherForecast.getString("temp_f"); 
 
\t  \t } catch (JSONException jse) { 
 
\t  \t Log.e(TAG, "Error parsing JSON", jse); 
 
\t  \t return; 
 
\t  \t } 
 
\t  \t } else { 
 
\t  \t Log.i(TAG, "String returned was Null, check doInBackground for errors"); 
 
\t  \t } 
 
\t  \t } 
 
\t  }

Я подумал, что лучший способ получить прогноз на каждый день - это запустить цикл на наборах JSON и просто распечатать «период», соответствующий каждому дню. Я, однако, не могу понять, как печатать вышеупомянутые данные о температуре и прогнозе с параметром, заданным циклом for с JSON.

Если кто-нибудь может помочь мне выяснить, как получить прогноз по текущему дню, я был бы счастлив. Но если бы я мог быть просвещен каким-либо другим способом, пожалуйста, дайте мне знать. Благодарю.

+0

Вы когда-нибудь пробовали библиотеку Джексона, чтобы разобрать все json в класс. – Giancarlo

+0

Знаете ли вы, если бы взглянули на сообщения об ошибках, у вас наверняка был бы ключ. –

ответ

2

Я вижу ошибку, вы пытаетесь получить JsonArray вместо JSONObject, чтобы подтвердить, что вы можете использовать следующую страницу, чтобы увидеть ваш JSon http://www.jsoneditoronline.org/

Вы можете изменить свой код. вот мой код.

@Override 
protected void onPostExecute(String result) { 
    super.onPostExecute(result); 
    if (result != null) { 
     Log.i(TAG, "result data was \n" + result); 
     try { 
      JSONObject jsonWeather = new JSONObject(result); 
      JSONObject weatherForecast = jsonWeather 
        .getJSONObject("forecast"); 
      JSONObject simpleForecast = weatherForecast 
        .getJSONObject("simpleforecast"); 
      JSONArray forecastArray = simpleForecast 
        .getJSONArray("forecastday"); 
      for (int i = 0; i < forecastArray.length(); i++) { 
       JSONObject fa = forecastArray.getJSONObject(i); 
       JSONObject highArray = fa.getJSONObject("high"); 
       //for (int h = 0; h < highArray.length(); h++) { 
        String fahrenheit = highArray.getString("fahrenheit"); 
        //JSONObject fahrenheit = ha.getJSONObject("fahrenheit"); 
        Log.v(TAG, "-fa-" + fahrenheit); 
        //break; 
       //} 
       String conditions = fa.getString("conditions"); 
       // JSONObject conditionsArray = 
       // fa.getJSONObject("conditions"); 
       // TextView output2 = (TextView)findViewById(R.id.fctext); 
       // output2.setText("" + conditions); 
       Log.v(TAG, "-Con-" + conditions); 
       break; 
      } 

      // String forecastArrayResult = 
      // weatherForecast.getString("temp_f"); 
     } catch (JSONException jse) { 
      Log.e(TAG, "Error parsing JSON", jse); 
      return; 
     } 
    } else { 
     Log.i(TAG, 
       "String returned was Null, check doInBackground for errors"); 
    } 
}