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;
}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM