Fediaa_92
20 уровень
Беларусь, Гомель

json на Android

Статья из группы Архив info.javarush
Это конечно не совсем java, но можете мне помочь. Нужно из json- файла достать некоторую информацию. Вот сам файл: { "response": { "version":"0.1", "termsofService":"http://www.wunderground.com/weather/api/d/terms.html", "features": { "forecast": 1 } } , "forecast":{ "txt_forecast": { "date":"5:11 PM FET", "forecastday": [ { "period":0, "icon":"partlycloudy", "icon_url":"http://icons.wxug.com/i/c/k/partlycloudy.gif", "title":"Friday", "fcttext":"Partly cloudy. Lows overnight in the low 50s.", "fcttext_metric":"Partly cloudy. Low 11C.", "pop":"0" } , { "period":1, "icon":"nt_partlycloudy", "icon_url":"http://icons.wxug.com/i/c/k/nt_partlycloudy.gif", "title":"Friday Night", "fcttext":"Partly cloudy skies. Low 51F. Winds ENE at 5 to 10 mph.", "fcttext_metric":"Partly cloudy. Low 11C. Winds ENE at 10 to 15 km/h.", "pop":"0" } , { "period":2, "icon":"partlycloudy", "icon_url":"http://icons.wxug.com/i/c/k/partlycloudy.gif", "title":"Saturday", "fcttext":"Sunshine and clouds mixed. High 74F. Winds E at 5 to 10 mph.", "fcttext_metric":"Partly cloudy skies. High 23C. Winds E at 10 to 15 km/h.", "pop":"0" } , { "period":3, "icon":"nt_partlycloudy", "icon_url":"http://icons.wxug.com/i/c/k/nt_partlycloudy.gif", "title":"Saturday Night", "fcttext":"Partly cloudy. Low 54F. Winds light and variable.", "fcttext_metric":"A few clouds from time to time. Low 12C. Winds light and variable.", "pop":"0" } , { "period":4, "icon":"partlycloudy", "icon_url":"http://icons.wxug.com/i/c/k/partlycloudy.gif", "title":"Sunday", "fcttext":"Intervals of clouds and sunshine. High 76F. Winds light and variable.", "fcttext_metric":"Intervals of clouds and sunshine. High 24C. Winds light and variable.", "pop":"0" } , { "period":5, "icon":"nt_partlycloudy", "icon_url":"http://icons.wxug.com/i/c/k/nt_partlycloudy.gif", "title":"Sunday Night", "fcttext":"Partly to mostly cloudy. Low around 55F. Winds ENE at 5 to 10 mph.", "fcttext_metric":"Partly cloudy skies during the evening will give way to cloudy skies overnight. Low 13C. Winds light and variable.", "pop":"0" } , { "period":6, "icon":"partlycloudy", "icon_url":"http://icons.wxug.com/i/c/k/partlycloudy.gif", "title":"Monday", "fcttext":"Sunshine and clouds mixed. High 76F. Winds light and variable.", "fcttext_metric":"Intervals of clouds and sunshine. High 24C. Winds light and variable.", "pop":"0" } , { "period":7, "icon":"nt_partlycloudy", "icon_url":"http://icons.wxug.com/i/c/k/nt_partlycloudy.gif", "title":"Monday Night", "fcttext":"Partly cloudy skies. Low 53F. Winds light and variable.", "fcttext_metric":"Partly cloudy skies. Low 12C. Winds light and variable.", "pop":"0" } ] }, "simpleforecast": { "forecastday": [ {"date":{ "epoch":"1409932800", "pretty":"7:00 PM FET on September 05, 2014", "day":5, "month":9, "year":2014, "yday":247, "hour":19, "min":"00", "sec":0, "isdst":"0", "monthname":"September", "monthname_short":"Sep", "weekday_short":"Fri", "weekday":"Friday", "ampm":"PM", "tz_short":"FET", "tz_long":"Europe/Minsk" }, "period":1, "high": { "fahrenheit":"71", "celsius":"21" }, "low": { "fahrenheit":"51", "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": null, "mm": null }, "qpf_night": { "in": 0.00, "mm": 0 }, "snow_allday": { "in": 0.0, "cm": 0.0 }, "snow_day": { "in": null, "cm": null }, "snow_night": { "in": 0.0, "cm": 0.0 }, "maxwind": { "mph": 13, "kph": 22, "dir": "East", "degrees": 0 }, "avewind": { "mph": 5, "kph": 8, "dir": "ENE", "degrees": 0 }, "avehumidity": 77, "maxhumidity": 0, "minhumidity": 0 } , {"date":{ "epoch":"1410019200", "pretty":"7:00 PM FET on September 06, 2014", "day":6, "month":9, "year":2014, "yday":248, "hour":19, "min":"00", "sec":0, "isdst":"0", "monthname":"September", "monthname_short":"Sep", "weekday_short":"Sat", "weekday":"Saturday", "ampm":"PM", "tz_short":"FET", "tz_long":"Europe/Minsk" }, "period":2, "high": { "fahrenheit":"74", "celsius":"23" }, "low": { "fahrenheit":"54", "celsius":"12" }, "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": 10, "kph": 16, "dir": "E", "degrees": 82 }, "avewind": { "mph": 7, "kph": 11, "dir": "E", "degrees": 82 }, "avehumidity": 63, "maxhumidity": 0, "minhumidity": 0 } , {"date":{ "epoch":"1410105600", "pretty":"7:00 PM FET on September 07, 2014", "day":7, "month":9, "year":2014, "yday":249, "hour":19, "min":"00", "sec":0, "isdst":"0", "monthname":"September", "monthname_short":"Sep", "weekday_short":"Sun", "weekday":"Sunday", "ampm":"PM", "tz_short":"FET", "tz_long":"Europe/Minsk" }, "period":3, "high": { "fahrenheit":"76", "celsius":"24" }, "low": { "fahrenheit":"55", "celsius":"13" }, "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": 10, "kph": 16, "dir": "ENE", "degrees": 73 }, "avewind": { "mph": 5, "kph": 8, "dir": "ENE", "degrees": 73 }, "avehumidity": 60, "maxhumidity": 0, "minhumidity": 0 } , {"date":{ "epoch":"1410192000", "pretty":"7:00 PM FET on September 08, 2014", "day":8, "month":9, "year":2014, "yday":250, "hour":19, "min":"00", "sec":0, "isdst":"0", "monthname":"September", "monthname_short":"Sep", "weekday_short":"Mon", "weekday":"Monday", "ampm":"PM", "tz_short":"FET", "tz_long":"Europe/Minsk" }, "period":4, "high": { "fahrenheit":"76", "celsius":"24" }, "low": { "fahrenheit":"53", "celsius":"12" }, "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": 10, "kph": 16, "dir": "E", "degrees": 94 }, "avewind": { "mph": 5, "kph": 8, "dir": "E", "degrees": 94 }, "avehumidity": 62, "maxhumidity": 0, "minhumidity": 0 } ] } } } И для этого файла был создан код, который в теории должен выводить всё, что мне нужно, но на практике я сталкиваюсь с ошибками Вот этот код: JSONObject fullData= new JSONObject (data); JSONArray forecast= fullData.get("forecast").get("simpleforecast").get("forecastday"); for (int i = 0; i < forecast.length(); i++) { JSONArray dayObject=forecast.get(i) int month=dayObject.get("date").getInt("month"); int year=dayObject.get("date").getInt("year"); int day=dayObject.get("date").getInt("day"); String icon=dayObject.getString("icon"); String condition=dayObject.getString("conditions"); String iconUrl=dayObject.getString("icon_url"); String highTemp=dayObject.get("high").getString("celsius"); String lowTemp=dayObject.get("low").getString("celsius"); } Помогите разобраться.
Комментарии (18)
ЧТОБЫ ПОСМОТРЕТЬ ВСЕ КОММЕНТАРИИ ИЛИ ОСТАВИТЬ КОММЕНТАРИЙ,
ПЕРЕЙДИТЕ В ПОЛНУЮ ВЕРСИЮ
tempys Уровень 31
6 сентября 2014
попробуй использувать библиотеку google Json, сам пользуюсь
Docktor91 Уровень 40
5 сентября 2014
JSONArray dayObject=forecast.get(i)

;
поставь)))))