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;
}
通过知识/经验的分享,节省开发者的时间.