笔者在Android开发中都是用的’Gson’进行的Json数据解析,但都说’FastJson’解析Json数据要比’Gson’快,笔者刚开始也是这么认为,至少它的名字中有’Fast’,所以笔者就在这里专门做了测试两者的解析性能
Gson版本:2.3.1
FastJson版本:1.1.43 android
项目 版本 GitHub Gson 2.3.1 https://github.com/google/gson FastJson 1.1.43 android https://github.com/alibaba/fastjson/wiki/Android%E7%89%88%E6%9C%AC
Test Jave Bean
//**中国区域级别Json数据JavaBean*/
public class AreasBean {
private String level;
private String parent_id;
private String name;
private String postcode;
private String id;
private List<AreasBean> subarea;
...get set...
}
Test Layout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<!--解析Json字符串至对象-->
<LinearLayout
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical">
<Button
android:textAl

本文通过测试对比了Gson 2.3.1和FastJson 1.1.43 android在Android环境下的Json解析性能。结果显示,尽管FastJson名称暗示其速度更快,但在多数场景下,Gson在解析Json到JavaBean以及循环解析时表现出更高的效率。然而,首次将JavaBean转换为Json时,FastJson略微领先,但后续调用中Gson始终更快。
最低0.47元/天 解锁文章
2038

被折叠的 条评论
为什么被折叠?



