0

I am seeing a problem if the JSON string is very big in that it simply does not fetch everything.

So I have a JSONparsing class based on popular example:

public String makeServiceCall(String url, int method,
        List<NameValuePair> params) {
    try {
        // http client
        DefaultHttpClient httpClient = new DefaultHttpClient();
        HttpEntity httpEntity = null;
        HttpResponse httpResponse = null;

        // Checking http request method type
        if (method == POST) {
            HttpPost httpPost = new HttpPost(url);
            // adding post params
            if (params != null) {
                httpPost.setEntity(new UrlEncodedFormEntity(params));
            }
            httpResponse = httpClient.execute(httpPost);
        } else if (method == GET) {
            // appending params to url
            if (params != null) {
                String paramString = URLEncodedUtils
                        .format(params, "utf-8");
                url += "?" + paramString;
            }
            HttpGet httpGet = new HttpGet(url);
            httpResponse = httpClient.execute(httpGet);
        }
        httpEntity = httpResponse.getEntity();

        if (httpEntity != null) {                 
            try {

                response= new String(EntityUtils.toString(httpEntity));
                Log.d(TAG, response);
            } 
            catch (ParseException exc) {
                // TODO Auto-generated catch block
                exc.printStackTrace();
            } catch (IllegalStateException exc) {
                // TODO Auto-generated catch block
                exc.printStackTrace();
            }

        }
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    return response;

}

Now what happens is that code of line

response= new String(EntityUtils.toString(httpEntity));

returns an incomplete string. If I make the JSON string smaller then its fine.

Does anyone know what I must do to get EntityUtils return me everything or give it a bigger buffer.

Thanks

drlobo
  • 2,139
  • 5
  • 32
  • 42

0 Answers0