我正在尝试从 stackexchange api 中检索一些数据。我做的很简单:
我得到这样的东西:
public JSONArray latestQuestions(String tagged)
{
String result = "";
JSONObject jArray = null;
JSONArray questions = null;
String link = api + "questions?order=desc&sort=activity&site=stackoverflow";
if(tagged != null)
{
link = api + "questions?order=desc&sort=activity&tagged=" + tagged + "&site=stackoverflow";
}
DefaultHttpClient client = new DefaultHttpClient();
try
{
Log.i(TAG + " latestQuestions",link);
HttpGet getQ = new HttpGet(link);
HttpResponse qResponse = client.execute(getQ);
HttpEntity entity = qResponse.getEntity();
if (entity != null)
{
result= EntityUtils.toString(entity, HTTP.UTF_8);
Log.d("JSON",result);
}
}
catch(Exception e)
{
Log.e(TAG + " latestQuestions","LOADING ERROR");
}
try
{
jArray = new JSONObject(result);
}
catch(JSONException e)
{
Log.e(TAG + " latestQuestions","JSON parsing error");
}
if(jArray != null)
{
try
{
questions = jArray.getJSONArray("items");
}
catch(JSONException e)
{
Log.d("JSON",result.toString());
}
}
return questions;
}
在哪里:
String api = "https://api.stackexchange.com/2.0/"