我正在尝试获取 DATA 数组中的信息,但一无所获。我正在从 Dark Sky API 解析这些数据:
hourly: {
summary: "Mostly cloudy later this morning.",
icon: "partly-cloudy-day",
data: [
{
time: 1364389200,
summary: "Partly Cloudy",
icon: "partly-cloudy-night",
precipIntensity: 0,
temperature: 29.8,
windSpeed: 2.44,
windBearing: 60,
cloudCover: 0.41,
humidity: 0.88,
pressure: 831.54,
visibility: 6.15
},
{
time: 1364392800,
summary: "Partly Cloudy",
icon: "partly-cloudy-day",
precipIntensity: 0,
temperature: 29.26,
windSpeed: 2.95,
windBearing: 45,
cloudCover: 0.36,
humidity: 0.88,
pressure: 832.05,
visibility: 6.14
}..................}
我想循环遍历数据数组。
我通过这样做获得每小时数据:
String hourly = json.getString("hourly");
但是,我没有从每小时字符串中获取数据数组。我错过了什么?
我在正确的道路上吗:
JSONObject h = json.getJSONObject("hourly");
String d = json.getString("data");
JSONArray a = h.getJSONArray("data");
for(int i = 0; i < a.length(); i++){
// Pulling items from the array
String s = h.getString("summary");
String t = h.getString("temperature");
aq.id(R.id.tv).text("Summary: " + s + "Temp: " + t);
}