2012-04-20 3 views
0

나는 stackexchange api에서 일부 데이터를 retrevie하려고합니다.안드로이드 - StackOverflow API

https://api.stackexchange.com/2.0/questions?order=desc&sort=activity&tagged=android&site=stackoverflow

과 나는 같은 것을 받고 : 나는 간단하고있어

enter image description here

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/" 
+0

음, 보인다. 코드의 관련 부분을 보지 않고서는 더 이상 알 수 없습니다. – Mat

+0

gzip/수축처럼 보입니까? – bzlm

+1

@bzlm gzip https://api.stackexchange.com/docs – Luksprog

답변