【发布时间】:2011-03-16 17:12:49
【问题描述】:
我正在尝试使用 gson 在 android 模拟器上进行对象映射。
处理 208 kb 左右的 json 数据时,速度慢得离谱。我的 json 中没有任何层次结构。
对象映射完成后,我可以看到gson创建了大约500条记录。
在 android 模拟器上映射输入 json 需要 3 多分钟。
我已经注释了由字符串和几个浮点数组成的实体。
我错过了什么?
任何想法、最佳实践都会有很大帮助。
有什么方法可以快速对json数据进行对象映射?
URL myURL = new URL(url);
/* Open a connection to that URL. */
URLConnection ucon = myURL.openConnection();
/*
* Define InputStreams to read from the URLConnection.
*/
InputStream is = ucon.getInputStream();
InputStreamReader reader = new InputStreamReader(is);
long tickCount = System.currentTimeMillis();
Policy[] policies = new Gson().fromJson(reader, Policy[].class);
long endCount = System.currentTimeMillis() - tickCount;
Log.d("Time to pull policies in milliseconds", "" + endCount);
【问题讨论】:
-
请不要使用安卓模拟器进行性能测量。它的性能模型与真实设备有很大不同。
标签: android performance gson