fastjson 是一个性能很好的 Java 语言实现的 JSON 解析器和生成器,来自阿里巴巴的工程师开发。
各个版本jar包下载地址:https://repo1.maven.org/maven2/com/alibaba/fastjson/
主要特点:
快速FAST (比其它任何基于Java的解析器和生成器更快,包括jackson)
强大(支持普通JDK类包括任意Java Bean Class、Collection、Map、Date或enum)
零依赖(没有依赖其它任何类库除了JDK)
使用说明:fastjson的最主要的使用入口是com.alibaba.fastjson.JSON,具体见下面代码:
package com.test; import java.util.HashMap;
import java.util.Map; import com.alibaba.fastjson.JSON;
import com.test.entity.User; public class FashJsonTest { public static void main(String[] args) {
//实体类 -->> json字符串
User user = new User("张三", "男", 26);
String userJson = JSON.toJSONString(user);
System.out.println(userJson);
//json字符串 -->> 实体类
User newUser = JSON.parseObject(userJson,User.class);
System.out.println(newUser.getName()); //Map -->> json字符串
Map <String,String> map = new HashMap<String,String>();
map.put("date", "2015-07-24");
System.out.println(JSON.toJSONString(map));
//Map -->> json字符串
Map <String,Object> objMap = new HashMap<String,Object>();
objMap.put("curUser", user);
System.out.println(JSON.toJSONString(objMap));
}
}
运行结果:
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAuwAAACACAIAAADf66ujAAAToElEQVR4nO2d2aGrOgxFqYuCqIcSXhU0QzF5Hwkg2ZIHMAk+d62vDOBBFtZGZhheAAAAAB0y/LoBAAAAAGdAxAAAAECXIGIAAACgSxAxAAAA0CWIGAAAAOgSRAwAAAB0CSIGAAAAugQRAwAAAF2CiAEAAIAuQcQAAABAl/xOxKzzOIzzemcVy3R3Dd+v6V9lmYZpeV1zmy+43N/jMNo2BP8antscB/06jx2Zxmlt1dHBofQIkofkOo//xhAhYiTrPA4HFfv6NTWSN8s0hLSYNT/F7kXdJcbWebzY4J+JmI+J3P3EyKgOxqZU3vXUmBcdAu1ETCrUi2pDK4qfhU0dT23gwFERV0TMMqXGWvfO+c/vT5HRbD+sFDHFNnk2R89t0zk2jwZRzcaWGfRR5I+iN4LbXzkTpw7JIg1j+Gf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