<!-- https://mvnrepository.com/artifact/com.alibaba/fastjson -->
<dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>fastjson</artifactId>
    <version>1.2.47</version>
</dependency>
 

 

package com.suning.sdipwd.controller.fourthPage;

import java.util.ArrayList;
import java.util.List;

import com.alibaba.fastjson.JSON;


public class MyTest {

    public static void main(String[] args) throws InstantiationException, IllegalAccessException, NoSuchMethodException, SecurityException {
        

        Person p1 = new Person();
        p1.setAge(1);
        p1.setName("zhangsan");
        String s = JSON.toJSONString(p1);
        System.out.println(s);
        
        String jsonPerson =  "{\"age\":1,\"name\":\"zhangsan\"}";
        Person p2 = JSON.parseObject(jsonPerson, Person.class);
        p2.setAge(2);
        p2.setName("lisi");
        System.out.println(p2);
        
        List<Person> list = new ArrayList<>();
        list.add(p1);
        list.add(p2);
        
        String listJson =  JSON.toJSONString(list);
        
        System.out.println(listJson);
        
        String listJson1 = "[{\"age\":1,\"name\":\"zhangsan\"},{\"age\":2,\"name\":\"lisi\"}]";
        
        List<Person> list1 = JSON.parseArray(listJson1, Person.class);
        System.out.println(list1);
    }
}

 

GitHub 加速计划 / fastj / fastjson
25.69 K
6.51 K
下载
FASTJSON 2.0.x has been released, faster and more secure, recommend you upgrade.
最近提交(Master分支:3 个月前 )
c942c834 - 1 年前
5bc4709b - 1 年前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐