阿里的json处理--fastjson
2016-10-26 17:20
357 查看
import java.util.HashMap; import java.util.List; import java.util.Map; import com.alibaba.fastjson.JSON; /** * json工具 */ public class JsonUtil { /** * 对象转 json */ public static String toJson( Object o ){ return JSON.toJSONString( o ); } /** * json转对象 */ public static <T> T toObject( String json , Class<T> clazz ){ return JSON.parseObject( json, clazz ); } /** * json转list对象 */ public static <T> List<T> toListObject(String json, Class<T> clazz ){ return JSON.parseArray( json, clazz); } /** * json转Map(支持多层级) */ @SuppressWarnings( "unchecked") public static Map<String, Object> toMap( String json ){ Map<String, Object> m = new HashMap<String, Object>(); try{ m = toObject( json, HashMap. class ); for( String k : m .keySet() ){ Object v = m.get( k ); if( v != null ){ String valStr = String. valueOf( v ); if( valStr .startsWith( "{" ) && valStr.endsWith( "}" ) ){ m.put( k, toMap( valStr ) ); } } } } catch( Exception e ){ } return m ; } }
相关文章推荐
- 阿里fastjson怎么处理时间格式
- 阿里fastjson怎么处理时间格式
- fastJson在java后台转换json格式数据探究(二)--处理数组/List/Map
- fastjson 对于json数组字符串的处理
- springmvc 使用fastjson 处理 json 数据时中文乱码
- fastjson 处理json字符串嵌套结构
- 阿里___FastJSON实现详解
- 阿里JSon开源组件fastjson应用
- FastJson、Jackson、Gson进行Java对象转换Json的细节处理
- fastjson对Date的处理
- fastjson对Date的处理
- java中对于JSON 的处理 fastjson gson 系统自带的JSON 的选择
- 【第15篇】通过FastJson把字符串转换成JSON和Map和List对象处理json数据
- fastjson null 值处理
- scala 调用 Java 的 fastjson 处理 json
- json处理第三篇:利用fastjson处理json
- 阿里fastjson的使用实例
- fastjson 嵌套对象,泛型的再次处理
- FastJson处理json数据时遇到一个问题
- Redis下实现序列化保存和使用FastJson的处理(java)