0
我想從stackexchange api retrevie一些數據。 我在做簡單:Android - StackOverflow 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/"
嗯,看起來你正在做的事情是錯誤的。在沒有看到代碼的相關部分的情況下,無法確切地說明這一點。 – Mat 2012-04-20 15:58:28
看起來像gzip/deflate? – bzlm 2012-04-20 16:02:59
@bzlm它是gzip https://api.stackexchange.com/docs – Luksprog 2012-04-20 16:28:38