Java基础-04 JSONObject 与范型对象转换

JSONObject 与范型对象转换

JSONObject resStr;
ResponseResult<AccountQuery> obj 
= JSONObject.parseObject(resStr.toString(),new TypeReference<ResponseResult<AccountQuery>>(){});

JSONObject 与范性对象转换

JSONObject resStr;
ResponseResult<AccountQuery> res 
= JSONObject.toJavaObject(resStr, ResponseResult.class);

测试数据

{
"mate":{"code":"0000","msg":"success"},
"result":{"acctStat":1,"balance":100},
"success":true
}

对象

@Data
public class ResponseResult<T> {
    private Mate mate;
    private T result;
    private Boolean success;
}

@Data
public class Mate {
    private String code;
    private String msg;
}
@Data
public class AccountQuery {
    private Long acctStat;
    private Long balance;
}
posted @ 2021-11-20 14:28  ysloong  阅读(1223)  评论(0编辑  收藏  举报