JsonUtil
来源:互联网 发布:unity3d与android交互 编辑:程序博客网 时间:2024/05/24 06:27
Fastjson is a Java library that can be used to convert Java Objects into their JSON representation. It can also be used to convert a JSON string to an equivalent Java object. Fastjson can work with arbitrary Java objects including pre-existing objects that you do not have source-code of.
Fastjson Goals
Provide best performance in server side and android client
Provide simple toJSONString() and parseObject() methods to convert Java objects to JSON and vice-versa
Allow pre-existing unmodifiable objects to be converted to and from JSON
Extensive support of Java Generics
Allow custom representations for objects
Support arbitrarily complex objects (with deep inheritance hierarchies and extensive use of generic types)
import com.alibaba.fastjson.JSON;import com.alibaba.fastjson.JSONArray;import com.alibaba.fastjson.serializer.SerializerFeature;import java.util.HashMap;import java.util.List;import java.util.Map;/** * JSON tool * */public class JsonUtil { public static String objectToJson(Object obj) { return JSON.toJSONString(obj); } public static String objectToJsonWithDateFormat(Object obj, String timeFormat, SerializerFeature serializerFeature) { return JSON.toJSONStringWithDateFormat(obj, timeFormat, serializerFeature); } public static <T> List<T> jsonToList(String jsonStr, Class<T> clazz) { return JSON.parseArray(jsonStr, clazz); } public static Map<String, Object> jsonToMap(String jsonStr) { return JSON.parseObject(jsonStr); } public static <T> T jsonToObject(String jsonStr, Class<T> clazz) { return JSON.parseObject(jsonStr, clazz); } @SuppressWarnings(value={"rawtypes"}) public static <T> List mapKeyGetList(Map map, String key, Class<T> clazz) { JSONArray arr = (JSONArray)map.get(key); return JSON.parseArray(arr.toString(), clazz); } @SuppressWarnings(value={"rawtypes"}) public static Map[] mapKeyGetMap(Map map, String key) { List<Map> list = mapKeyGetList(map, key, Map.class); return list.toArray(new HashMap[list.size()]); }}
- JsonUtil
- JsonUtil
- JsonUtil
- JSONUtil
- JsonUtil
- JsonUtil
- JsonUtil
- JsonUtil
- JsonUtil实例
- jackson jsonUtil
- android-jsonUtil
- jsonutil 学习使用
- jsonutil的使用
- Java - JSONUtil.java
- JSON工具类JSONUtil
- JsonUtil 学习使用
- JsonUtil工具类
- Json工具类 ---JsonUtil
- POJ 1328 Radar Installation
- es6 封装ajax
- python 操纵数据库(1) 连接数据库
- 已知前序、中序,递归建立二叉树(C语言)
- aac转码后的数据无法直接播放
- JsonUtil
- ios -静默方式发送邮件
- 2017陕西省ACM省赛总结
- 面向切面编程的应用场景
- oj 1914: 找零钱
- github上传code指南
- Linux下Python环境的搭建
- android自定义view系列:认识activity结构
- 成长,从你发现自己写的代码很LOW开始