ここで私はjsonの応答の結果がありますが、私は予測配列にアクセスするための正しいコードを取得する必要があります。JavaのJSON配列の要素をアクセス
{
"query": {
"count": 1,
"created": "2016-10-23T02:37:21Z",
"lang": "en-US",
"results": {
"channel": {
"units": {
"distance": "mi",
"pressure": "in",
"speed": "mph",
"temperature": "F"
},
"title": "Yahoo! Weather - Kingston, Saint Andrew, JM",
"link": "http://us.rd.yahoo.com/dailynews/rss/weather/Country__Country/*https://weather.yahoo.com/country/state/city-109251/",
"description": "Yahoo! Weather for Kingston, Saint Andrew, JM",
"language": "en-us",
"lastBuildDate": "Sat, 22 Oct 2016 09:37 PM EST",
"ttl": "60",
"location": {
"city": "Kingston",
"country": "Jamaica",
"region": " Saint Andrew"
},
"wind": {
"chill": "77",
"direction": "0",
"speed": "0"
},
"atmosphere": {
"humidity": "90",
"pressure": "988.0",
"rising": "0",
"visibility": "15.3"
},
"astronomy": {
"sunrise": "6:3 am",
"sunset": "5:40 pm"
},
"image": {
"title": "Yahoo! Weather",
"width": "142",
"height": "18",
"link": "http://weather.yahoo.com",
"url": "http://l.yimg.com/a/i/brand/purplelogo//uh/us/news-wea.gif"
},
"item": {
"title": "Conditions for Kingston, Saint Andrew, JM at 09:00 PM EST",
"lat": "18.015711",
"long": "-76.79731",
"link": "http://us.rd.yahoo.com/dailynews/rss/weather/Country__Country/*https://weather.yahoo.com/country/state/city-109251/",
"pubDate": "Sat, 22 Oct 2016 09:00 PM EST",
"condition": {
"code": "27",
"date": "Sat, 22 Oct 2016 09:00 PM EST",
"temp": "77",
"text": "Mostly Cloudy"
},
"forecast": [
{
"code": "4",
"date": "22 Oct 2016",
"day": "Sat",
"high": "80",
"low": "75",
"text": "Thunderstorms"
},
{
"code": "4",
"date": "23 Oct 2016",
"day": "Sun",
"high": "80",
"low": "75",
"text": "Thunderstorms"
},
{
"code": "4",
"date": "24 Oct 2016",
"day": "Mon",
"high": "80",
"low": "76",
"text": "Thunderstorms"
},
{
"code": "4",
"date": "25 Oct 2016",
"day": "Tue",
"high": "80",
"low": "74",
"text": "Thunderstorms"
},
{
"code": "4",
"date": "26 Oct 2016",
"day": "Wed",
"high": "80",
"low": "75",
"text": "Thunderstorms"
},
{
"code": "4",
"date": "27 Oct 2016",
"day": "Thu",
"high": "80",
"low": "75",
"text": "Thunderstorms"
},
{
"code": "4",
"date": "28 Oct 2016",
"day": "Fri",
"high": "78",
"low": "74",
"text": "Thunderstorms"
}
],
"guid": {
"isPermaLink": "false"
}
}
}
}
}
}
これは私が試していたものですが、動作しませんでした。予測JSONArrayに正しくアクセスする必要があります。正しい表記法は何ですか?
public void populate(JSONObject data) throws JSONException {
JSONArray jArr = data.getJSONObject("item").getJSONObject("condition").getJSONArray("forecast");
for(int i=0;i<jArr.length();i++){
JSONObject jDayForecast = jArr.getJSONObject(i);
String date = jDayForecast.getString("date");
String text = jDayForecast.getString("text");
}
}配列を予測するための参照を取得していないよう
は、この行は常にnullを返しますか?
JSONArray jArr = data.getJSONArray( "forecast");
あなたが移入するために何を渡しています関数 ?! –