我在 J2ME 中工作。
我从服务器收到 json 响应,然后我尝试根据我的要求解析这个 json 数据。
这是我从服务器获取响应的代码:-
InputStream inputStream = null;
OutputStreamWriter out = null;
byte[] readData = new byte[50000];
String response = "no";
try {
// --- write ---
out = new OutputStreamWriter(connection.openOutputStream(), "UTF-8");
out.write(data.toString());
out.close();
// --- read ---
int responseCode = connection.getResponseCode();
if (responseCode != HttpConnection.HTTP_OK) {
throw new IOException("HTTP response code: " + responseCode);
}
inputStream = connection.openInputStream();
int actual = inputStream.read(readData);
response = new String(readData, 0, actual, "UTF-8");
return response;
}
当来自服务器的响应很小时,它可以正常工作,但是如果响应很大,那么它会得到一半的响应并返回到我的另一个方法。请建议我应该怎么做才能将大量数据放入我的readData和响应变量中。
先感谢您。