json解析——fastjson

来源:互联网 发布:淘宝卖家快递推荐 编辑:程序博客网 时间:2024/05/27 10:43
使用fastjson首先要下载jar包 http://code.alibabatech.com/mvn/releases/com/alibaba/fastjson/1.0.4/fastjson-1.0.4.jar
假设有两个实体:
        student:id,name,age
        teacher:id,name,students
将实体解析为json字符串:
        Student student = new Student(0, "lisi", 1);  
        System.out.println(JSON.toJSONString(student));  
        System.out.println(JSON.toJSONString(student,true));  按照标准的json格式输出
       自定义需要序列化的字段
              SimplePropertyPreFilter filter = new SimplePropertyPreFilter(实体类.class"字段1","字段2"); 
              JSON.toJSONString(students,filter); 
将json字符串反序列化为实体:
              JSON.parseObject(str,Student.class);  
更详细内容参考:http://www.cnblogs.com/Jie-Jack/p/3758046.html
原创粉丝点击