我正在尝试获取以下 JSON 中显示的第一张图片:
{
"hourly_forecast": [{
"FCTTIME": {
"hour": "0",
"hour_padded": "00",
"min": "00",
"sec": "0",
"year": "2013",
"mon": "10",
"mon_padded": "10",
"mon_abbrev": "Oct",
"mday": "30",
"mday_padded": "30",
"yday": "302",
"isdst": "0",
"epoch": "1383087600",
"pretty": "12:00 AM CET on October 30, 2013",
"civil": "12:00 AM",
"month_name": "October",
"month_name_abbrev": "Oct",
"weekday_name": "Wednesday",
"weekday_name_night": "Wednesday Night",
"weekday_name_abbrev": "Wed",
"weekday_name_unlang": "Wednesday",
"weekday_name_night_unlang": "Wednesday Night",
"ampm": "AM",
"tz": "",
"age": ""
},
"temp": {
"english": "47",
"metric": "8"
},
"dewpoint": {
"english": "44",
"metric": "6"
},
"condition": "Mostly Cloudy",
"icon": "mostlycloudy",
"icon_url": "http://icons-ak.wxug.com/i/c/k/nt_mostlycloudy.gif",
"fctcode": "3",
"sky": "71",
"wspd": {
"english": "11",
"metric": "18"
},
"wdir": {
"dir": "SW",
"degrees": "231"
},
"wx": "",
"uvi": "0",
"humidity": "86",
"windchill": {
"english": "-9998",
"metric": "-9998"
},
"heatindex": {
"english": "-9998",
"metric": "-9998"
},
"feelslike": {
"english": "47",
"metric": "8"
},
"qpf": {
"english": "",
"metric": ""
},
"snow": {
"english": "",
"metric": ""
},
"pop": "10",
"mslp": {
"english": "29.93",
"metric": "1013"
}
},
每小时重复一次,但我只需要第一张图像。如何制作一个AyncTask
只返回标签“icon_url”找到的第一张图片?
我到目前为止的代码:
protected Void doInBackground(String... params) {
String response = null;
String url = "http://api.wunderground.com/api/apikey/hourly/q/CA/"
+ toStation + ".json";
Time now = new Time();
now.setToNow();
try {
HttpClient client = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(url);
ResponseHandler<String> handler = new BasicResponseHandler();
response = client.execute(httpGet, handler);
JSONArray list = new JSONArray(response);
for (int i = 0; i < list.length(); i++) {
JSONObject wheatherObj = list.getJSONObject(i);
Wheather wheather = new Wheather(wheatherObj);
if(wheather.getTime()==now.hour+"") {
<what needs to be here>
}
}