Android JSON解析不会获取完整的字符串

时间:2014-04-27 12:13:16

标签: android json androidhttpclient android-json

如果JSON字符串非常大,我看到一个问题,因为它根本无法获取所有内容。

所以我有一个基于流行示例的JSONparsing类:

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;

}

现在发生的是行代码

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

返回不完整的字符串。 如果我把JSON字符串缩小,那就好了。

有没有人知道我必须做些什么才能让EntityUtils给我一切回报或给它一个更大的缓冲区。

由于

0 个答案:

没有答案