1

I'm trying to retrevie some data from stackexchange api. I'm doing simple:

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

and I getting something like this:

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;
}

where:

String api = "https://api.stackexchange.com/2.0/"
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
goodm
  • 7,275
  • 6
  • 31
  • 55
  • Well, looks like you're doing something wrong. Can't really tell more than that without seeing the relevant parts of your code. – Mat Apr 20 '12 at 15:58
  • Looks like gzip/deflate? – bzlm Apr 20 '12 at 16:02
  • 1
    @bzlm It is gzip https://api.stackexchange.com/docs – user Apr 20 '12 at 16:28
  • @Luksprog, in that case, possible duplicate of [automatically handling gzip http responses in Android](http://stackoverflow.com/questions/7139268/automatically-handling-gzip-http-responses-in-android) – bzlm Apr 22 '12 at 09:50

1 Answers1

3

The response should be compressed... GZip... check out some of their documentation.

In particular: https://api.stackexchange.com/docs/compression

To handle decompressing the data check out this link: http://developer.android.com/reference/java/util/zip/GZIPInputStream.html

Daniel
  • 23,129
  • 12
  • 109
  • 154