json解析数据

1、解析里外2层嵌套list的数据为单层list

private List> currentPosition;

数据:
[[Position(position=研究员, orgName=合肥研究院, orgId=71070)]]

解析代码

        Person person = new Person();
        //1、先转为jsonString
        String s = JSON.toJSONString(person.getCurrentPosition());
        //2、去掉多余的[]
        s = s.substring(1, s.length() -1);
        //3、再转回jsonString
        List positions = JSON.parseArray(s).toJavaList(Position.class);
        person.setCurrentPositionTest(positions);
        System.out.println(JSON.toJSONString(person, true));

实体类代码

public class Person {

    private List> currentPosition;

    private List currentPositionTest;
}

 

你可能感兴趣的:(Java,java,json)