========================
java项目代做请加q 1768566220
========================
场景: 可用在http调用后参数转换
例子如下: 将json字符串转为一个外层对象包了一个里层对象
转换前json字符串如下:
{
"data": {
"pageNum": 0,
"pageSize": 0,
"totalPages": 0,
"total": 303,
"orderBy": null,
"content": [{
"payDateTime": "",
"orderNumber": "91563401200930822",
"organName": "举例中心医院",
"organCode": "70000",
"doctorName": "张某",
"doctorCode": "080088",
"patientName": "龚女子",
"medicalCardNum": "0000000539",
"channelCode": "APP",
"orderStatus": 2,
"money": "6.00"
} ],
}
}
转换代码如下:
||
||
||
||
\/
||
||
||
||
\/
||
||
||
||
\/
||
||
||
||
\/
||
||
||
||
\/
||
||
||
||
\/
||
||
||
||
\/
//通过key将value对象值拿到
String data = jsonObject.getString("data");
//先转换外层对象
HxPage hxPage = JsonUtil.convertObject(data, HxPage.class);
//将外层对象转以下,通过key取内层对象
JSONObject dataObject = JSONObject.parseObject(data);
JSONArray jsonArray =dataObject.getJSONArray("content");
//转内层对象
List<QueryOrderListResVO> list= jsonArray.toJavaList(QueryOrderListResVO.class);
//将内层对象设置为外层对象的属性
hxPage.setContent(list);
提示:如果有多层对象的话,就需要分层取对象再作转换
==感谢阅读,希望我的分享能够帮助到你,如有不对尽情指正。