1 Star 1 Fork 0

chenjim / JsonParser

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

JsonParser

@TOC

首先说说Gson和Fastjson的相关使用,详细博文 链接点我

都说FastJson更快,为什么那么快呢,已有许多博文解析,比如 链接点我

测试代码

全部 代码地址

                Student student = initStudent();
                String json = "";
                long time0;

                time0 = SystemClock.elapsedRealtime();
                for (int i = 0; i < FOR_NUM; i++) {
//                    gson = new Gson();
                    json = gson.toJson(student);
                }
                Log.d(TAG, "Gson Object to json time:" + (SystemClock.elapsedRealtime() - time0));
                //Log.d(TAG, "Gson Object to json :" + json);

                time0 = SystemClock.elapsedRealtime();
                for (int i = 0; i < FOR_NUM; i++) {
//                    gson = new Gson();
                    student = gson.fromJson(json, Student.class);
                }
                Log.d(TAG, "Gson json to Object time:" + (SystemClock.elapsedRealtime() - time0));

                time0 = SystemClock.elapsedRealtime();
                for (int i = 0; i < FOR_NUM; i++) {
                    json = JSON.toJSONString(student);
                }
                Log.d(TAG, "JSON Object to json time:" + (SystemClock.elapsedRealtime() - time0));
                //                Log.d(TAG, "JSON Object to json :" + json);

                time0 = SystemClock.elapsedRealtime();
                for (int i = 0; i < FOR_NUM; i++) {
                    student = JSON.parseObject(json, Student.class);
                }
                Log.d(TAG, "JSON json to Object time:" + (SystemClock.elapsedRealtime() - time0));

                //Log.d(TAG, "result:" + JSON.toJSONString(student));

测试结果

05-06 14:05:28.261 19015 19126 D GsonFastjson: Gson Object to json time:225
05-06 14:05:28.473 19015 19126 D GsonFastjson: Gson json to Object time:211
05-06 14:05:28.648 19015 19126 D GsonFastjson: JSON Object to json time:176
05-06 14:05:28.927 19015 19126 D GsonFastjson: JSON json to Object time:279

测试结论

  • FastJson将对象转json字符串更快一些
  • FastJson将json转对象稍微慢一些

空文件

简介

Gson和Fastjson效率的对比 展开 收起
Android
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Android
1
https://gitee.com/chenjim/JsonParser.git
git@gitee.com:chenjim/JsonParser.git
chenjim
JsonParser
JsonParser
master

搜索帮助