Fastjson
1.Fastjson概述
fastjson是阿里开源的用于JSON处理的库,号称最快的JSON处理库,我一直使用fastjson快5年差不多40多个大大小小的项目了,从来没出过问题.
最新的是fastjson2, 基于maven引用方法:
<dependency>
<groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2</artifactId>
<version>2.0.49</version>
</dependency>
2.JSON数组常见操作
2.1.创建JSON数组
JSONArray items_array= new JSONArray();
2.2.JSON数组添加元素
JSONObject focus_item = new JSONObject();
item.put("id", 999);
item.put("title", "Hi");
items_array.add(item);
2.3.遍历JSON数组并获取元素值
for(int i=0; i<items_array.size(); i++) {
JSONObject item = items_array.getJSONObject(i);
Long id = item.getLong("id");
}
参考资料:
1.《fastjson2在github的开源网址》, https://github.com/alibaba/fastjson2