1

stackexchange api からデータを取得しようとしています。私は簡単にやっています:

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

そして私はこのようなものを得ます:

ここに画像の説明を入力

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/"
4

1 に答える 1

3

応答は圧縮する必要があります... GZip...ドキュメントのいくつかをチェックしてください。

特に: https://api.stackexchange.com/docs/compression

データの解凍を処理するには、次のリンクを確認してください: http://developer.android.com/reference/java/util/zip/GZIPInputStream.html

于 2012-04-27T14:48:41.947 に答える