【发布时间】:2013-05-22 13:25:04
【问题描述】:
我目前正在使用此代码从我的服务器中使用 JsonStrings 创建对象:
JsonParser parser = new JsonParser();
JsonObject myJsonObject = (JsonObject) parser.parse(myInputStreamReader);
MyObject myObject = new Gson().fromJson(myJsonObject.toString(), MyObject.class);
这在大多数情况下工作得很好,但有时,对象非常大,因此myJsonObject.toString() 会导致java.lang.OutOfMemoryError。是否有可能将JsonObjects 直接转换为指定的对象而不先将它们转换为字符串?
我已经通过使用StreamReader 而不是String 绕过OutOfMemmoryError 来创建JsonObject,现在我又遇到了完全相同的问题,只是下面几行:/
【问题讨论】:
标签: java android json casting gson