处理巨大的JSON…
通知
清除所有

处理巨大的JSON响应

RSS

(@sathish)
成员 主持人
加入:1年前
帖子:1391
16/06/2021十二21点

我认为我需要重写我的应用程序的一些模块,因为当实体的数量被渲染的增加,它失败和错误。现在,我在利用杰克逊httpcliend.尽管我信任杰克逊,但直觉告诉我问题出在第二个lib。可以Httpcliend处理大的响应?(如。这一个大概有400行)

除此之外,在我的应用程序中,我解析请求的方式是这样的:

公共对象处理(HttpResponse response, String rootName)试一试{String json = EntityUtils.toString(response.getEntity());//更好的"new BasicResponseHandler().handleResponse(response)"????intstatusCode = response.getStatusLine () .getStatusCode ();如果(statusCode > =200& & statusCode <300){返回createObject (json, rootName);}其他的返回;}}(异常e) {RuntimeException (e);}}公共对象createObject(String json, String rootName)试一试.root =.mapper.readTree (json);String className = findclassname (rootName);类clazz =.getObjectClass(名称);返回mapper.treeToValue (root.get (rootName) clazz);}(异常e) {RuntimeException (e);}}

我如何改进这段代码,以更有效的大响应?


报价
(@abhijith)
贵族成员
加入:1年前
帖子:1350
16/06/2021十二24点

没有必要创建Json字符串,因为objectmap # readtree可以接受一个inputStream也例如,这样会更有效率:

公共对象处理(HttpResponse response, String rootName)试一试intstatusCode = response.getStatusLine () .getStatusCode ();如果(statusCode > =200& & statusCode <300){返回createObject (response.getEntity () .getContent (), rootName);}其他的返回;}}(异常e) {RuntimeException (e);}}公共对象createObject(InputStream json, String rootName)试一试.root =.mapper.readTree (json);String className = findclassname (rootName);类clazz =.getObjectClass(名称);返回mapper.treeToValue (root.get (rootName) clazz);}(异常e) {RuntimeException (e);}}

回复报价
分享:
Baidu