我在阅读这个 api 时遇到问题
http://api.xhanch.com/islamic-get-prayer-time.php?lng=67&lat=24&yy=2012&mm=7&gmt=5&m=json
这是我的代码:
new Read().execute("sunrise");
public JSONObject retrieveInfo(String user) throws ClientProtocolException,IOException, JSONException {
StringBuilder url = new StringBuilder(URL);
url.append(user);
HttpGet get = new HttpGet(url.toString());
HttpResponse r = client.execute(get);
HttpEntity e = r.getEntity();
String data = EntityUtils.toString(e);
JSONArray timeline = new JSONArray(data);
JSONObject last = timeline.getJSONObject(1);
return last;
}
public class Read extends AsyncTask<String, Integer, String> {
protected String doInBackground(String... arg0) {
// TODO Auto-generated method stub
try {
json = retrieveInfo("");
return json.getString(arg0[0]);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
这个方法总是返回一个空白字符串而不是我需要的信息。