Fast_JSON

作者: 安安静静写代码 | 来源:发表于2017-08-28 21:40 被阅读66次

    Fast_JSON是阿里推出的一种Json解析的一种方式,它的用法与GSON相似,但是比GSON还要简便
    解析

    package com.qf.demo5;
    
    import com.alibaba.fastjson.JSON;
    import com.qf.demo.Person;
    
    public class Test {
    
        public static void main(String[] args) {
            String string  = "{name:'zhangsan',age:20}";
            // Gson 创建对象   fromJson
            // fast-json     Json.parseObject
            Person person = JSON.parseObject(string,Person.class);
            System.out.println(person);
        }
    }
    
    

    反向操作

    package com.qf.demo5;
    
    import com.alibaba.fastjson.JSON;
    import com.qf.demo.Person;
    
    /**
     * 利用fast-json 创建json字符串
     * @author Administrator
     *
     */
    public class Test2 {
    
        public static void main(String[] args) {
            Person person = new Person("zhangsan", 45);
            String string = JSON.toJSONString(person);
            System.out.println(string);
        }
    }
    

    相关文章

      网友评论

          本文标题:Fast_JSON

          本文链接:https://www.haomeiwen.com/subject/zefpdxtx.html