JSONObject

Posted xjatj

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JSONObject相关的知识,希望对你有一定的参考价值。

 JSONObject paramJson = JSONObject.parseObject(param);
        if (!paramJson.containsKey("peerTime")) {
            throw new BaseException(ErrorCodeEnum.CODE_DB_CONNECT_ERROR, "set peer param must contains param peerTime");
        }
数组
"statisticsInfo": [{ "idType": 0, "id": "1234567" },{ "idType": 1, "id": "1234567" }]
List<JSONObject> statisticsInfoJson = JSONArray
.parseArray((paramJson.get("statisticsInfo")).toString(), JSONObject.class);
List<StatisticsIdEntity> statisticsIds = new ArrayList<>(statisticsInfoJson.size());
for (JSONObject jsonObject : statisticsInfoJson) {
StatisticsIdEntity statisticsIdEntity = new StatisticsIdEntity();
statisticsIdEntity.setIdType(Short.valueOf(String.valueOf(jsonObject.get("idType"))));
statisticsIdEntity.setIdValue(String.valueOf(jsonObject.get("id")));
statisticsIds.add(statisticsIdEntity);
}
 

参数格式如下(areaCode是区域码,deviceId是点位id)

[{

       "areaCode": "12345",

       "deviceId": "12345"

},

{

       "areaCode": "12346",

       "deviceId": "12346"

}]

List<Map> areDeviceIds=JSONArray.parseArray(areaDeviceIds, Map.class)

 












以上是关于JSONObject的主要内容,如果未能解决你的问题,请参考以下文章