fastjson 总结

前端之家收集整理的这篇文章主要介绍了fastjson 总结前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

(1)序列化

1.1 对象(User):

String text = JSON.toJSONString(user /*,SerializerFeature.UseSingleQuotes */);

1.2 list / map / set集合:

String text=JSON.toJSONString(users/*,SerializerFeature.UseSingleQuotes*/);

(2)反序列化

2.1 对象(User): eg: {"name":"愿望 ","stime":1377087488762}

User u=JSON.parSEObject(text,User.class);

2.2 list集合 eg: [{"name":"张三","stime":1377087570508},{"name":"李四","stime":1377087570508}]

List<User> list = JSON.parseArray(text,User.class);

2.3 map集合 eg: {1:{"name":"张三","stime":1377087637172},2:{"name":"李四","stime":1377087637172}}

Map<Long,User> userMap = JSON.parSEObject(text,new TypeReference<Map<Long,User>>() {});

2.4 set集合 eg: [{"name":"李四","stime":1377087674850},{"name":"张三","stime":1377087674850}]

Set<User> userMap = JSON.parSEObject(text,new TypeReference<Set<User>>(){});

  • 附件几个testcase
原文链接:https://www.f2er.com/json/290064.html

猜你在找的Json相关文章