2014-09-08 2 views
0

고맙습니다.자바 3 레벨 JSON 구문 분석

Weather Underground API에서 JSON 배열을 구문 분석하려고합니다. 예측> txt_forecast> {아이콘, icon_url, 제목, fcttext} : 내가 드릴 다운하기 위해 노력하고있어

{ 
    "response": { 
    "version": "0.1", 
    "termsofService": "http://www.wunderground.com/weather/api/d/terms.html", 
    "features": { 
    "forecast10day": 1 
    } 
    }, 
    "forecast": { 
    "txt_forecast": { 
    "date": "8:00 AM PDT", 
    "forecastday": [{ 
    "period": 0, 
    "icon": "partlycloudy", 
    "icon_url": "http://icons-ak.wxug.com/i/c/k/partlycloudy.gif", 
    "title": "Tuesday", 
    "fcttext": "Overcast in the morning, then clear. High of 75F. Winds from the SSW at 5 to 20 mph.", 
    "fcttext_metric": "Overcast in the morning, then clear. High of 24C. Windy. Winds from the SSW at 5 to 30 km/h.", 
    "pop": "0" 
    }, { 
    "period": 1, 
    "icon": "partlycloudy", 
    "icon_url": "http://icons-ak.wxug.com/i/c/k/partlycloudy.gif", 
    "title": "Tuesday Night", 
    "fcttext": "Mostly cloudy. Low of 55F. Winds from the SW at 5 to 15 mph.", 
    "fcttext_metric": "Mostly cloudy. Low of 13C. Breezy. Winds from the SW at 10 to 20 km/h.", 
    "pop": "0" 
    }, { 
    "period": 2, 
    "icon": "partlycloudy", 
    "icon_url": "http://icons-ak.wxug.com/i/c/k/partlycloudy.gif", 
    "title": "Wednesday", 
    "fcttext": "Mostly cloudy in the morning, then clear. High of 72F. Winds from the SW at 10 to 15 mph.", 
    "fcttext_metric": "Mostly cloudy in the morning, then clear. High of 22C. Breezy. Winds from the SW at 15 to 25 km/h.", 
    "pop": "0" 
    }, { 
    "period": 3, 
    "icon": "partlycloudy", 
    "icon_url": "http://icons-ak.wxug.com/i/c/k/partlycloudy.gif", 
    "title": "Wednesday Night", 
    "fcttext": "Mostly cloudy. Fog overnight. Low of 55F. Winds from the SW at 10 to 15 mph.", 
    "fcttext_metric": "Mostly cloudy. Fog overnight. Low of 13C. Breezy. Winds from the SW at 15 to 20 km/h.", 
    "pop": "0" 
    }, { 
    "period": 4, 
    "icon": "partlycloudy", 
    "icon_url": "http://icons-ak.wxug.com/i/c/k/partlycloudy.gif", 
    "title": "Thursday", 
    "fcttext": "Mostly cloudy. Fog early. High of 70F. Winds from the WSW at 10 to 15 mph.", 
    "fcttext_metric": "Mostly cloudy. Fog early. High of 21C. Windy. Winds from the WSW at 15 to 25 km/h.", 
    "pop": "0" 
    }, { 
    "period": 5, 
    "icon": "clear", 
    "icon_url": "http://icons-ak.wxug.com/i/c/k/clear.gif", 
    "title": "Thursday Night", 
    "fcttext": "Partly cloudy. Fog overnight. Low of 55F. Winds from the WNW at 5 to 10 mph.", 
    "fcttext_metric": "Partly cloudy. Fog overnight. Low of 13C. Winds from the WNW at 10 to 15 km/h.", 
    "pop": "0" 
    }, { 
    "period": 6, 
    "icon": "partlycloudy", 
    "icon_url": "http://icons-ak.wxug.com/i/c/k/partlycloudy.gif", 
    "title": "Friday", 
    "fcttext": "Partly cloudy in the morning, then clear. High of 72F. Winds from the West at 5 to 15 mph.", 
    "fcttext_metric": "Partly cloudy in the morning, then clear. High of 22C. Breezy. Winds from the West at 10 to 20 km/h.", 
    "pop": "0" 
    }, { 
    "period": 7, 
    "icon": "partlycloudy", 
    "icon_url": "http://icons-ak.wxug.com/i/c/k/partlycloudy.gif", 
    "title": "Friday Night", 
    "fcttext": "Partly cloudy. Fog overnight. Low of 55F. Winds from the WNW at 5 to 10 mph.", 
    "fcttext_metric": "Partly cloudy. Fog overnight. Low of 13C. Winds from the WNW at 10 to 15 km/h.", 
    "pop": "0" 
    }, { 
    "period": 8, 
    "icon": "partlycloudy", 
    "icon_url": "http://icons-ak.wxug.com/i/c/k/partlycloudy.gif", 
    "title": "Saturday", 
    "fcttext": "Partly cloudy. Fog early. High of 73F. Winds from the West at 5 to 15 mph.", 
    "fcttext_metric": "Partly cloudy. Fog early. High of 23C. Breezy. Winds from the West at 10 to 20 km/h.", 
    "pop": "0" 
    }, { 
    "period": 9, 
    "icon": "partlycloudy", 
    "icon_url": "http://icons-ak.wxug.com/i/c/k/partlycloudy.gif", 
    "title": "Saturday Night", 
    "fcttext": "Clear. Fog overnight. Low of 55F. Winds from the West at 5 to 10 mph.", 
    "fcttext_metric": "Clear. Fog overnight. Low of 13C. Winds from the West at 10 to 15 km/h.", 
    "pop": "0" 
    }, { 
    "period": 10, 
    "icon": "partlycloudy", 
    "icon_url": "http://icons-ak.wxug.com/i/c/k/partlycloudy.gif", 
    "title": "Sunday", 
    "fcttext": "Partly cloudy. High of 72F. Winds from the West at 5 to 15 mph.", 
    "fcttext_metric": "Partly cloudy. High of 22C. Breezy. Winds from the West at 10 to 20 km/h.", 
    "pop": "0" 
    }, { 
    "period": 11, 
    "icon": "partlycloudy", 
    "icon_url": "http://icons-ak.wxug.com/i/c/k/partlycloudy.gif", 
    "title": "Sunday Night", 
    "fcttext": "Partly cloudy. Fog overnight. Low of 55F. Winds from the West at 5 to 10 mph.", 
    "fcttext_metric": "Partly cloudy. Fog overnight. Low of 13C. Winds from the West at 10 to 15 km/h.", 
    "pop": "0" 
    }, { 
    "period": 12, 
    "icon": "partlycloudy", 
    "icon_url": "http://icons-ak.wxug.com/i/c/k/partlycloudy.gif", 
    "title": "Monday", 
    "fcttext": "Clear. High of 70F. Winds from the West at 5 to 10 mph.", 
    "fcttext_metric": "Clear. High of 21C. Breezy. Winds from the West at 10 to 20 km/h.", 
    "pop": "0" 
    }, { 
    "period": 13, 
    "icon": "partlycloudy", 
    "icon_url": "http://icons-ak.wxug.com/i/c/k/partlycloudy.gif", 
    "title": "Monday Night", 
    "fcttext": "Partly cloudy. Fog overnight. Low of 55F. Winds from the West at 5 to 10 mph.", 
    "fcttext_metric": "Partly cloudy. Fog overnight. Low of 13C. Winds from the West at 5 to 15 km/h.", 
    "pop": "0" 
    }, { 
    "period": 14, 
    "icon": "partlycloudy", 
    "icon_url": "http://icons-ak.wxug.com/i/c/k/partlycloudy.gif", 
    "title": "Tuesday", 
    "fcttext": "Clear. High of 75F. Winds from the West at 5 to 10 mph.", 
    "fcttext_metric": "Clear. High of 24C. Breezy. Winds from the West at 10 to 20 km/h.", 
    "pop": "0" 
    }, { 
    "period": 15, 
    "icon": "clear", 
    "icon_url": "http://icons-ak.wxug.com/i/c/k/clear.gif", 
    "title": "Tuesday Night", 
    "fcttext": "Clear. Low of 59F. Winds from the West at 5 to 15 mph.", 
    "fcttext_metric": "Clear. Low of 15C. Breezy. Winds from the West at 10 to 20 km/h.", 
    "pop": "0" 
    }, { 
    "period": 16, 
    "icon": "partlycloudy", 
    "icon_url": "http://icons-ak.wxug.com/i/c/k/partlycloudy.gif", 
    "title": "Wednesday", 
    "fcttext": "Clear. High of 73F. Winds from the West at 5 to 15 mph.", 
    "fcttext_metric": "Clear. High of 23C. Winds from the West at 5 to 20 km/h.", 
    "pop": "0" 
    }, { 
    "period": 17, 
    "icon": "clear", 
    "icon_url": "http://icons-ak.wxug.com/i/c/k/clear.gif", 
    "title": "Wednesday Night", 
    "fcttext": "Clear. Low of 59F. Winds from the West at 5 to 15 mph.", 
    "fcttext_metric": "Clear. Low of 15C. Breezy. Winds from the West at 10 to 20 km/h.", 
    "pop": "0" 
    }, { 
    "period": 18, 
    "icon": "clear", 
    "icon_url": "http://icons-ak.wxug.com/i/c/k/clear.gif", 
    "title": "Thursday", 
    "fcttext": "Clear. High of 73F. Winds from the West at 5 to 15 mph.", 
    "fcttext_metric": "Clear. High of 23C. Winds from the West at 5 to 20 km/h.", 
    "pop": "0" 
    }, { 
    "period": 19, 
    "icon": "clear", 
    "icon_url": "http://icons-ak.wxug.com/i/c/k/clear.gif", 
    "title": "Thursday Night", 
    "fcttext": "Clear. Low of 57F. Winds from the WSW at 5 to 10 mph.", 
    "fcttext_metric": "Clear. Low of 14C. Winds from the WSW at 10 to 15 km/h.", 
    "pop": "0" 
    }] 
    }, 
    "simpleforecast": { 
    "forecastday": [{ 
    "date": { 
    "epoch": "1341381600", 
    "pretty": "11:00 PM PDT on July 03, 2012", 
    "day": 3, 
    "month": 7, 
    "year": 2012, 
    "yday": 184, 
    "hour": 23, 
    "min": "00", 
    "sec": 0, 
    "isdst": "1", 
    "monthname": "July", 
    "weekday_short": "Tue", 
    "weekday": "Tuesday", 
    "ampm": "PM", 
    "tz_short": "PDT", 
    "tz_long": "America/Los_Angeles" 
    }, 
    "period": 1, 
    "high": { 
    "fahrenheit": "75", 
    "celsius": "24" 
    }, 
    "low": { 
    "fahrenheit": "55", 
    "celsius": "13" 
    }, 
    "conditions": "Partly Cloudy", 
    "icon": "partlycloudy", 
    "icon_url": "http://icons-ak.wxug.com/i/c/k/partlycloudy.gif", 
    "skyicon": "mostlysunny", 
    "pop": 0, 
    "qpf_allday": { 
    "in": 0.00, 
    "mm": 0.0 
    }, 
    "qpf_day": { 
    "in": 0.00, 
    "mm": 0.0 
    }, 
    "qpf_night": { 
    "in": 0.00, 
    "mm": 0.0 
    }, 
    "snow_allday": { 
    "in": 0, 
    "cm": 0 
    }, 
    "snow_day": { 
    "in": 0, 
    "cm": 0 
    }, 
    "snow_night": { 
    "in": 0, 
    "cm": 0 
    }, 
    "maxwind": { 
    "mph": 17, 
    "kph": 27, 
    "dir": "WSW", 
    "degrees": 255 
    }, 
    "avewind": { 
    "mph": 14, 
    "kph": 22, 
    "dir": "WSW", 
    "degrees": 241 
    }, 
    "avehumidity": 72, 
    "maxhumidity": 82, 
    "minhumidity": 62 
    }, { 
    "date": { 
    "epoch": "1341468000", 
    "pretty": "11:00 PM PDT on July 04, 2012", 
    "day": 4, 
    "month": 7, 
    "year": 2012, 
    "yday": 185, 
    "hour": 23, 
    "min": "00", 
    "sec": 0, 
    "isdst": "1", 
    "monthname": "July", 
    "weekday_short": "Wed", 
    "weekday": "Wednesday", 
    "ampm": "PM", 
    "tz_short": "PDT", 
    "tz_long": "America/Los_Angeles" 
    }, 
    "period": 2, 
    "high": { 
    "fahrenheit": "72", 
    "celsius": "22" 
    }, 
    "low": { 
    "fahrenheit": "55", 
    "celsius": "13" 
    }, 
    "conditions": "Partly Cloudy", 
    "icon": "partlycloudy", 
    "icon_url": "http://icons-ak.wxug.com/i/c/k/partlycloudy.gif", 
    "skyicon": "partlycloudy", 
    "pop": 0, 
    "qpf_allday": { 
    "in": 0.00, 
    "mm": 0.0 
    }, 
    "qpf_day": { 
    "in": 0.00, 
    "mm": 0.0 
    }, 
    "qpf_night": { 
    "in": 0.00, 
    "mm": 0.0 
    }, 
    "snow_allday": { 
    "in": 0, 
    "cm": 0 
    }, 
    "snow_day": { 
    "in": 0, 
    "cm": 0 
    }, 
    "snow_night": { 
    "in": 0, 
    "cm": 0 
    }, 
    "maxwind": { 
    "mph": 15, 
    "kph": 24, 
    "dir": "WSW", 
    "degrees": 237 
    }, 
    "avewind": { 
    "mph": 12, 
    "kph": 19, 
    "dir": "SW", 
    "degrees": 231 
    }, 
    "avehumidity": 79, 
    "maxhumidity": 89, 
    "minhumidity": 54 
    }, { 
    "date": { 
    "epoch": "1341554400", 
    "pretty": "11:00 PM PDT on July 05, 2012", 
    "day": 5, 
    "month": 7, 
    "year": 2012, 
    "yday": 186, 
    "hour": 23, 
    "min": "00", 
    "sec": 0, 
    "isdst": "1", 
    "monthname": "July", 
    "weekday_short": "Thu", 
    "weekday": "Thursday", 
    "ampm": "PM", 
    "tz_short": "PDT", 
    "tz_long": "America/Los_Angeles" 
    }, 
    "period": 3, 
    "high": { 
    "fahrenheit": "70", 
    "celsius": "21" 
    }, 
    "low": { 
    "fahrenheit": "55", 
    "celsius": "13" 
    }, 
    "conditions": "Partly Cloudy", 
    "icon": "partlycloudy", 
    "icon_url": "http://icons-ak.wxug.com/i/c/k/partlycloudy.gif", 
    "skyicon": "mostlysunny", 
    "pop": 0, 
    "qpf_allday": { 
    "in": 0.00, 
    "mm": 0.0 
    }, 
    "qpf_day": { 
    "in": 0.00, 
    "mm": 0.0 
    }, 
    "qpf_night": { 
    "in": 0.00, 
    "mm": 0.0 
    }, 
    "snow_allday": { 
    "in": 0, 
    "cm": 0 
    }, 
    "snow_day": { 
    "in": 0, 
    "cm": 0 
    }, 
    "snow_night": { 
    "in": 0, 
    "cm": 0 
    }, 
    "maxwind": { 
    "mph": 15, 
    "kph": 24, 
    "dir": "West", 
    "degrees": 265 
    }, 
    "avewind": { 
    "mph": 13, 
    "kph": 21, 
    "dir": "WSW", 
    "degrees": 250 
    }, 
    "avehumidity": 77, 
    "maxhumidity": 87, 
    "minhumidity": 64 
    }, { 
    "date": { 
    "epoch": "1341640800", 
    "pretty": "11:00 PM PDT on July 06, 2012", 
    "day": 6, 
    "month": 7, 
    "year": 2012, 
    "yday": 187, 
    "hour": 23, 
    "min": "00", 
    "sec": 0, 
    "isdst": "1", 
    "monthname": "July", 
    "weekday_short": "Fri", 
    "weekday": "Friday", 
    "ampm": "PM", 
    "tz_short": "PDT", 
    "tz_long": "America/Los_Angeles" 
    }, 
    "period": 4, 
    "high": { 
    "fahrenheit": "72", 
    "celsius": "22" 
    }, 
    "low": { 
    "fahrenheit": "55", 
    "celsius": "13" 
    }, 
    "conditions": "Partly Cloudy", 
    "icon": "partlycloudy", 
    "icon_url": "http://icons-ak.wxug.com/i/c/k/partlycloudy.gif", 
    "skyicon": "sunny", 
    "pop": 0, 
    "qpf_allday": { 
    "in": 0.00, 
    "mm": 0.0 
    }, 
    "qpf_day": { 
    "in": 0.00, 
    "mm": 0.0 
    }, 
    "qpf_night": { 
    "in": 0.00, 
    "mm": 0.0 
    }, 
    "snow_allday": { 
    "in": 0, 
    "cm": 0 
    }, 
    "snow_day": { 
    "in": 0, 
    "cm": 0 
    }, 
    "snow_night": { 
    "in": 0, 
    "cm": 0 
    }, 
    "maxwind": { 
    "mph": 11, 
    "kph": 18, 
    "dir": "West", 
    "degrees": 272 
    }, 
    "avewind": { 
    "mph": 9, 
    "kph": 14, 
    "dir": "West", 
    "degrees": 274 
    }, 
    "avehumidity": 70, 
    "maxhumidity": 84, 
    "minhumidity": 58 
    }, { 
    "date": { 
    "epoch": "1341727200", 
    "pretty": "11:00 PM PDT on July 07, 2012", 
    "day": 7, 
    "month": 7, 
    "year": 2012, 
    "yday": 188, 
    "hour": 23, 
    "min": "00", 
    "sec": 0, 
    "isdst": "1", 
    "monthname": "July", 
    "weekday_short": "Sat", 
    "weekday": "Saturday", 
    "ampm": "PM", 
    "tz_short": "PDT", 
    "tz_long": "America/Los_Angeles" 
    }, 
    "period": 5, 
    "high": { 
    "fahrenheit": "73", 
    "celsius": "23" 
    }, 
    "low": { 
    "fahrenheit": "55", 
    "celsius": "13" 
    }, 
    "conditions": "Fog", 
    "icon": "partlycloudy", 
    "icon_url": "http://icons-ak.wxug.com/i/c/k/partlycloudy.gif", 
    "skyicon": "mostlysunny", 
    "pop": 0, 
    "qpf_allday": { 
    "in": 0.00, 
    "mm": 0.0 
    }, 
    "qpf_day": { 
    "in": 0.00, 
    "mm": 0.0 
    }, 
    "qpf_night": { 
    "in": 0.00, 
    "mm": 0.0 
    }, 
    "snow_allday": { 
    "in": 0, 
    "cm": 0 
    }, 
    "snow_day": { 
    "in": 0, 
    "cm": 0 
    }, 
    "snow_night": { 
    "in": 0, 
    "cm": 0 
    }, 
    "maxwind": { 
    "mph": 11, 
    "kph": 18, 
    "dir": "West", 
    "degrees": 266 
    }, 
    "avewind": { 
    "mph": 9, 
    "kph": 14, 
    "dir": "West", 
    "degrees": 270 
    }, 
    "avehumidity": 75, 
    "maxhumidity": 85, 
    "minhumidity": 61 
    }, { 
    "date": { 
    "epoch": "1341813600", 
    "pretty": "11:00 PM PDT on July 08, 2012", 
    "day": 8, 
    "month": 7, 
    "year": 2012, 
    "yday": 189, 
    "hour": 23, 
    "min": "00", 
    "sec": 0, 
    "isdst": "1", 
    "monthname": "July", 
    "weekday_short": "Sun", 
    "weekday": "Sunday", 
    "ampm": "PM", 
    "tz_short": "PDT", 
    "tz_long": "America/Los_Angeles" 
    }, 
    "period": 6, 
    "high": { 
    "fahrenheit": "72", 
    "celsius": "22" 
    }, 
    "low": { 
    "fahrenheit": "55", 
    "celsius": "13" 
    }, 
    "conditions": "Fog", 
    "icon": "partlycloudy", 
    "icon_url": "http://icons-ak.wxug.com/i/c/k/partlycloudy.gif", 
    "skyicon": "partlycloudy", 
    "pop": 0, 
    "qpf_allday": { 
    "in": 0.00, 
    "mm": 0.0 
    }, 
    "qpf_day": { 
    "in": 0.00, 
    "mm": 0.0 
    }, 
    "qpf_night": { 
    "in": 0.00, 
    "mm": 0.0 
    }, 
    "snow_allday": { 
    "in": 0, 
    "cm": 0 
    }, 
    "snow_day": { 
    "in": 0, 
    "cm": 0 
    }, 
    "snow_night": { 
    "in": 0, 
    "cm": 0 
    }, 
    "maxwind": { 
    "mph": 11, 
    "kph": 18, 
    "dir": "West", 
    "degrees": 265 
    }, 
    "avewind": { 
    "mph": 9, 
    "kph": 14, 
    "dir": "West", 
    "degrees": 266 
    }, 
    "avehumidity": 79, 
    "maxhumidity": 88, 
    "minhumidity": 66 
    }, { 
    "date": { 
    "epoch": "1341900000", 
    "pretty": "11:00 PM PDT on July 09, 2012", 
    "day": 9, 
    "month": 7, 
    "year": 2012, 
    "yday": 190, 
    "hour": 23, 
    "min": "00", 
    "sec": 0, 
    "isdst": "1", 
    "monthname": "July", 
    "weekday_short": "Mon", 
    "weekday": "Monday", 
    "ampm": "PM", 
    "tz_short": "PDT", 
    "tz_long": "America/Los_Angeles" 
    }, 
    "period": 7, 
    "high": { 
    "fahrenheit": "70", 
    "celsius": "21" 
    }, 
    "low": { 
    "fahrenheit": "55", 
    "celsius": "13" 
    }, 
    "conditions": "Partly Cloudy", 
    "icon": "partlycloudy", 
    "icon_url": "http://icons-ak.wxug.com/i/c/k/partlycloudy.gif", 
    "skyicon": "mostlysunny", 
    "pop": 0, 
    "qpf_allday": { 
    "in": 0.00, 
    "mm": 0.0 
    }, 
    "qpf_day": { 
    "in": 0.00, 
    "mm": 0.0 
    }, 
    "qpf_night": { 
    "in": 0.00, 
    "mm": 0.0 
    }, 
    "snow_allday": { 
    "in": 0, 
    "cm": 0 
    }, 
    "snow_day": { 
    "in": 0, 
    "cm": 0 
    }, 
    "snow_night": { 
    "in": 0, 
    "cm": 0 
    }, 
    "maxwind": { 
    "mph": 10, 
    "kph": 16, 
    "dir": "West", 
    "degrees": 263 
    }, 
    "avewind": { 
    "mph": 9, 
    "kph": 14, 
    "dir": "West", 
    "degrees": 269 
    }, 
    "avehumidity": 85, 
    "maxhumidity": 92, 
    "minhumidity": 67 
    }, { 
    "date": { 
    "epoch": "1341986400", 
    "pretty": "11:00 PM PDT on July 10, 2012", 
    "day": 10, 
    "month": 7, 
    "year": 2012, 
    "yday": 191, 
    "hour": 23, 
    "min": "00", 
    "sec": 0, 
    "isdst": "1", 
    "monthname": "July", 
    "weekday_short": "Tue", 
    "weekday": "Tuesday", 
    "ampm": "PM", 
    "tz_short": "PDT", 
    "tz_long": "America/Los_Angeles" 
    }, 
    "period": 8, 
    "high": { 
    "fahrenheit": "75", 
    "celsius": "24" 
    }, 
    "low": { 
    "fahrenheit": "59", 
    "celsius": "15" 
    }, 
    "conditions": "Partly Cloudy", 
    "icon": "partlycloudy", 
    "icon_url": "http://icons-ak.wxug.com/i/c/k/partlycloudy.gif", 
    "skyicon": "sunny", 
    "pop": 0, 
    "qpf_allday": { 
    "in": 0.00, 
    "mm": 0.0 
    }, 
    "qpf_day": { 
    "in": 0.00, 
    "mm": 0.0 
    }, 
    "qpf_night": { 
    "in": 0.00, 
    "mm": 0.0 
    }, 
    "snow_allday": { 
    "in": 0, 
    "cm": 0 
    }, 
    "snow_day": { 
    "in": 0, 
    "cm": 0 
    }, 
    "snow_night": { 
    "in": 0, 
    "cm": 0 
    }, 
    "maxwind": { 
    "mph": 10, 
    "kph": 16, 
    "dir": "West", 
    "degrees": 264 
    }, 
    "avewind": { 
    "mph": 8, 
    "kph": 13, 
    "dir": "West", 
    "degrees": 263 
    }, 
    "avehumidity": 78, 
    "maxhumidity": 90, 
    "minhumidity": 58 
    }, { 
    "date": { 
    "epoch": "1342072800", 
    "pretty": "11:00 PM PDT on July 11, 2012", 
    "day": 11, 
    "month": 7, 
    "year": 2012, 
    "yday": 192, 
    "hour": 23, 
    "min": "00", 
    "sec": 0, 
    "isdst": "1", 
    "monthname": "July", 
    "weekday_short": "Wed", 
    "weekday": "Wednesday", 
    "ampm": "PM", 
    "tz_short": "PDT", 
    "tz_long": "America/Los_Angeles" 
    }, 
    "period": 9, 
    "high": { 
    "fahrenheit": "73", 
    "celsius": "23" 
    }, 
    "low": { 
    "fahrenheit": "59", 
    "celsius": "15" 
    }, 
    "conditions": "Partly Cloudy", 
    "icon": "partlycloudy", 
    "icon_url": "http://icons-ak.wxug.com/i/c/k/partlycloudy.gif", 
    "skyicon": "mostlysunny", 
    "pop": 0, 
    "qpf_allday": { 
    "in": 0.00, 
    "mm": 0.0 
    }, 
    "qpf_day": { 
    "in": 0.00, 
    "mm": 0.0 
    }, 
    "qpf_night": { 
    "in": 0.00, 
    "mm": 0.0 
    }, 
    "snow_allday": { 
    "in": 0, 
    "cm": 0 
    }, 
    "snow_day": { 
    "in": 0, 
    "cm": 0 
    }, 
    "snow_night": { 
    "in": 0, 
    "cm": 0 
    }, 
    "maxwind": { 
    "mph": 11, 
    "kph": 18, 
    "dir": "West", 
    "degrees": 273 
    }, 
    "avewind": { 
    "mph": 8, 
    "kph": 13, 
    "dir": "West", 
    "degrees": 268 
    }, 
    "avehumidity": 76, 
    "maxhumidity": 93, 
    "minhumidity": 58 
    }, { 
    "date": { 
    "epoch": "1342159200", 
    "pretty": "11:00 PM PDT on July 12, 2012", 
    "day": 12, 
    "month": 7, 
    "year": 2012, 
    "yday": 193, 
    "hour": 23, 
    "min": "00", 
    "sec": 0, 
    "isdst": "1", 
    "monthname": "July", 
    "weekday_short": "Thu", 
    "weekday": "Thursday", 
    "ampm": "PM", 
    "tz_short": "PDT", 
    "tz_long": "America/Los_Angeles" 
    }, 
    "period": 10, 
    "high": { 
    "fahrenheit": "73", 
    "celsius": "23" 
    }, 
    "low": { 
    "fahrenheit": "57", 
    "celsius": "14" 
    }, 
    "conditions": "Clear", 
    "icon": "clear", 
    "icon_url": "http://icons-ak.wxug.com/i/c/k/clear.gif", 
    "skyicon": "sunny", 
    "pop": 0, 
    "qpf_allday": { 
    "in": 0.00, 
    "mm": 0.0 
    }, 
    "qpf_day": { 
    "in": 0.00, 
    "mm": 0.0 
    }, 
    "qpf_night": { 
    "in": 0.00, 
    "mm": 0.0 
    }, 
    "snow_allday": { 
    "in": 0, 
    "cm": 0 
    }, 
    "snow_day": { 
    "in": 0, 
    "cm": 0 
    }, 
    "snow_night": { 
    "in": 0, 
    "cm": 0 
    }, 
    "maxwind": { 
    "mph": 11, 
    "kph": 18, 
    "dir": "West", 
    "degrees": 268 
    }, 
    "avewind": { 
    "mph": 8, 
    "kph": 13, 
    "dir": "West", 
    "degrees": 263 
    }, 
    "avehumidity": 71, 
    "maxhumidity": 89, 
    "minhumidity": 53 
    }] 
    } 
    } 
} 

다음과 같이 나는 10 일간의 일기 예보에 대한 받고 있어요 반환이다.

저는 현재 제대로 작동하지 않는 전용 JSONParser 클래스를 사용하고 있습니다. 그것은 현재 다음과 같습니다

package com.garciaericn.forecaster.data; 

import android.util.Log; 

import org.json.JSONArray; 
import org.json.JSONException; 
import org.json.JSONObject; 

import java.util.ArrayList; 
import java.util.List; 

/** 
* Full Sail University 
* Mobile Development BS 
* Created by ENG618-Mac on 9/7/14. 
*/ 
public class JSONParser { 

    public static final String TAG = "JSONParser.TAG"; 


    public static List<Weather> parseForecast(String jsonString) { 
     Log.i(TAG, "parseForecast entered"); 

     List<Weather> weatherJSON = new ArrayList<Weather>(); 

     try { 
      // Create JSON 
      JSONObject data = new JSONObject(jsonString); 

      // Create Array of weather objects 
      JSONArray forecast = new JSONArray(data.getJSONArray("forecast").toString()); 
      JSONObject txtForecast = forecast.getJSONObject("txt_forecast"); 
      JSONObject simpeForecast = forecast.getJSONObject(Integer.parseInt("simpleforecast")); 

      // Loop through recipesJSON for desired info 
      for (int i = 0; i < txtForecast.length(); i++) { 
       Log.i(TAG, "In for loop at index: " + i + " Object: " + forecast.getJSONObject(i)); 

       // This is where I was tring to obtain those fields 
      } 

     } catch (JSONException e) { 
      e.printStackTrace(); 
     } 

     Log.i(TAG, "JSON array: " + weatherJSON); 

     return weatherJSON; 
    } 
} 
+0

신뢰할 수있는 파서는 문제가 없습니다. 당신은 그것이 무엇인지 이해할 필요가 있습니다. json.org로 가서 구문을 연구하십시오. 배우는 데 5-10 분 밖에 걸리지 않으며 그 다음에는 더 많은 의미가 있습니다. JSON의 구조에 따라 코드가 달라야하므로 다른 사람의 JSON 처리 코드를 복사하는 것은 일반적으로 바보입니다. –

+0

(코드에서 여러 가지 일들이 발생합니다. 본질적으로 말도 안됩니다.) –

+0

(불행히도 JSON은 너무 길기 때문에 서식을 게시 할 수 없지만 http : //에서 붙여 넣기하여 볼 수 있습니다. json.parser.online.fr/이 들여 쓰기는 이해하기가 훨씬 쉬울 것입니다.) –

답변

1

JSON에서 배열 [로 시작하고 객체가 {로 시작합니다. forecast 그래서이

JSONArray forecast = new JSONArray(data.getJSONArray("forecast").toString()); 

또한, forecastday 배열이

JSONObject forecast = new JSONObject(data.getJSONObject("forecast").toString()); 

에 변경하여 JSON의 배열이 아닙니다. 논리를 적절하게 변경하십시오.

+0

감사합니다. 이것은 내가 잘못 가고있는 곳을 이해하는 데 정말로 도움이되었습니다. – ENG618

0

여기 나와 함께 시도해 보았습니다.

try { 
    // Create JSON 
    JSONObject data = new JSONObject(jsonString); 

    // Create Array of weather objects 
    JSONObject forecast = new JSONObject(data.getJSONObject("forecast").toString()); 
    JSONObject txtForecast = new JSONObject(forecast.getJSONObject("txt_forecast").toString()); 
    JSONArray forecastDay = txtForecast.getJSONArray("forecastday"); 


    // TODO: Add more details to weather object with following info. 
    //JSONObject simpleForecast = forecast.getJSONObject(forecast.getJSONObject("simpleforecast").toString()); 
    //JSONArray simpleForecastDay = simpleForecast.getJSONArray("forecastday"); 

    // Loop through recipesJSON for desired info 
    for (int i = 0; i < forecastDay.length(); i++) { 
     Log.i(TAG, "In for loop at index: " + i + " Object: " + forecastDay.getJSONObject(i)); 

     // Obtain Fields 
     String dayOfWeek = forecastDay.getJSONObject(i).getString("title"); 
     String condition = forecastDay.getJSONObject(i).getString("icon"); 
     String forecastText = forecastDay.getJSONObject(i).getString("fcttext"); 
     String iconURL = forecastDay.getJSONObject(i).getString("icon_url"); 

     // Create instance of Weather 
     Weather tempWeather = new Weather(dayOfWeek, condition, forecastText, iconURL); 

     weatherJSON.add(tempWeather); 
    } 
} catch (JSONException e) { 
    e.printStackTrace(); 
}