我从{em> class1 到 class2 提交了InputStream
in 。现在,我想将 class2 中的InputStream
解析为JSONObject
。
try {
JsonElement element = new JsonParser().parse(new InputStreamReader(in));
JSONObject jsonObject = new JSONObject(element.getAsJsonObject().toString());
} catch (JSONException e) {
System.err.println(e.getMessage());
}
我的JsonElement
是 null 。所以我没有JSONObject
。
我在 class1 中使用了相同的代码,并且可以正常工作。唯一的区别是InputStream
是在 class1 中与HTTPHandler.execute(...)
生成的。
class1 提交与{em> class2 正确的InputStream
。