maven:

<dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>1.2.73</version>
        </dependency>

解析字符串,获取值:

String str = "{code:1}";
 String str = "{code:'123'}";
 JSONObject jsonObject = JSON.parseObject(str);
 Integer code = jsonObject.getInteger("code");
 String code = jsonObject.getString("code");

 User:{
    id:Integer,
   name: String
 }

解析字符串,转为模型对象:

  String data1 = "{id:1,name:'abc'}";
 User user = JSON.parseObject(data1, User.class);

道法自然