我想解析來自php服務器的json響應。但是當我嘗試登錄並使用時,我只能在手機上獲得部分響應。但在瀏覽器加載url時,我得到了完整的響應。在調試模式下,響應字符串變量具有完整數據Android在手機中獲取部分json字符串響應,但在瀏覽器中獲得完整響應
HttpPost httpPost = new HttpPost(url);
httpPost.setEntity(new UrlEncodedFormEntity(params));
httpResponse = httpClient.execute(httpPost);
httpEntity = httpResponse.getEntity();
if (httpEntity != null) {
// A Simple JSON Response Read
InputStream instream = httpEntity.getContent();
response = convertStreamToString(instream);
// now you have the string representation of the HTML request
instream.close();
}
private static String convertStreamToString(InputStream is) {
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
StringBuilder sb = new StringBuilder();
String line = null;
try {
while ((line = reader.readLine()) != null) {
sb.append(line);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
is.close();
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return sb.toString();
}
我目前有在這裏同樣的問題:http://stackoverflow.com/questions/29223980/json-string-cut-off-half-way -java-inputstream你是否設法解決這個問題? – Zy0n