【发布时间】:2016-12-06 16:54:18
【问题描述】:
这是我的JSON,
{
"city": {
"id": 2961297,
"name": "Swords",
"coord": {
"lon": -6.21806,
"lat": 53.459721
},
"country": "IE",
"population": 0
},
"cod": "200",
"message": 0.3535,
"cnt": 1,
"list": [
{
"dt": 1481025600,
"temp": {
"day": 284.68,
"min": 284.68,
"max": 285.36,
"night": 285.36,
"eve": 284.8,
"morn": 284.68
},
"pressure": 1028.26,
"humidity": 95,
"weather": [
{
"id": 500,
"main": "Rain",
"description": "light rain",
"icon": "10d"
}
],
"speed": 9.01,
"deg": 186,
"clouds": 92,
"rain": 0.5
}
]
}
我正在尝试访问上面返回的 JSON 数据中看到的雨值 "rain": 0.5 我不确定如何执行此操作,因为我没有太多使用 JSON 数据的经验。
这是我的代码,
JSONObject topLevel = new JSONObject(builder.toString());
JSONArray ListArray = topLevel.getJSONArray("list");
weather = String.valueOf(ListArray);
for(int x = 0;x < ListArray.length();x++) {
JSONObject myObj = ListArray.getJSONObject(x);
myObj.getInt("rain");
Log.d("TODAYS Rain"+rain,"");
//System.out.Print("Current Weather" +id+main+icon+dscription+rain);
}
非常感谢任何帮助。
【问题讨论】:
-
你的日志现在有什么内容?
-
它正在返回 JSON 数据中的所有内容,但是当我尝试将它附加到我已经修复的文本字段时告诉它不存在雨谢谢
标签: java android json openweathermap