1.list转jsonString
List<DataModel> dataList = new ArrayList();
String respstr= JSON.toJSONString(dataList, SerializerFeature.DisableCircularReferenceDetect);
2.jsonString转list
-
jsonStrList 为 [{
“ms”:“xxxx”,
“indi”:“xxxx”,
“date”:“2018‐11‐21 12:00:00”,
“value”:1232.45
},{
“ms”:“xxxx”,
“indi”:“xxxx”,
“date”:“2018‐11‐21 11:00:00”,
“value”:2334.56
}]
List<DataModel> dataModelList = JSONObject.parseArray(jsonStrList, DataModel.class); -
jsonStrList 为 {
“errorCode” : 0,
“errorMessage” : null,
“data” : {
“total” : 2,
“pageNo” : 1,
“pageSize” : 10,
“list” : [
{
“userUuid” : “xxxxx1”,
“loginAccount” : “test1”,
“userName” : “测试”
},
{
“userUuid” : “xxxxx2”,
“loginAccount” : “test2”,
“userName” : “测试”
}
]
}
}
JSONObject jsonObject = JSONObject.parseObject(jsonStr);
JSONObject jan = (JSONObject) jsonObject.get(“data”);
JSONArray jsonDataList = jan.getJSONArray(“list”);
List<DoorDevice> doorDeviceList = JSONObject.parseArray(jsonDataList.toJSONString(), DoorDevice.class); -
jsonStrList 为{
“errorCode” : 0,
“errorMessage” : null,
“data” : “f0b93a745cc911e8b2bdd771b6792897”
}
JSONObject jsonObject = JSONObject.parseObject(jsonStrList);
String DefaultUserUUID = jsonObject.getString(“data”); -
jsonStrList 为{
“errorCode” : 0,
“errorMessage” : null,
“data” : {
“ms”:“xxxx”,
“indi”:“xxxx”,
“date”:“2018‐11‐21 11:00:00”,
“value”:12342.45
}
}
JSONObject jsonObject = JSONObject.parseObject(jsonStr);
JSONObject jan = (JSONObject) jsonObject.get(“data”);
EBikeStatus eBikeStatus = JSONObject.parseObject(jan.toJSONString(), EBikeStatus.class);
- jsonStrList 为{
“errorCode” : 0,
“errorMessage” : null,
“data” : [{
“ms”:“xxxx”,
“indi”:“xxxx”,
“date”:“2018‐11‐21 12:00:00”,
“value”:12342.45
},{
“ms”:“xxxx”,
“indi”:“xxxx”,
“date”:“2018‐11‐21 11:00:00”,
“value”:23344.56
}]
}
JSONObject jsonObject = JSONObject.parseObject(jsonStr);
JSONArray jsonDataList = jsonObject .getJSONArray(“data”);
List<DoorDevice> doorDeviceList = JSONObject.parseArray(jsonDataList.toJSONString(), DoorDevice.class);