Java解析json字符串

#task_content
{
  "begin":xxx,
  "end":xxx,
  "deviceIds":["uuid1","uuid2"]
}

#file_url
[
  {"uuid1":"fileid"},{"uuid2":"fileid2"}
]
@Override
    public List<UploadTaskCenterVO> uploadTaskCenter(UploadTaskCenterDto uploadTaskCenterDto) {
        String tenantId = RequestContext.getCurrentSession().getTenantId();
        TaskCenterDO taskCenterDO = taskCenterManager.getByIdAndTenantId(uploadTaskCenterDto.getId(), tenantId);
        //得到deviceIds里面的uuid1
        List<Object> list = new ArrayList<>();
        String taskContent = taskCenterDO.getTaskContent();
        JSONObject jsonObject1 = JSONObject.parseObject(taskContent);
        JSONArray deviceIds = jsonObject1.getJSONArray("deviceIds");
        for (int j = 0; j < deviceIds.size(); j++) {
            Object o = deviceIds.get(j);
            list.add(o);
        }
        //根据uuid1得到fileId
        String fileUrl = taskCenterDO.getFileUrl();
        JSONArray jsonArray = JSON.parseArray(fileUrl);
        List<String> fileIdList = new ArrayList<>();
        for (int i = 0; i < jsonArray.size(); i++) {
            JSONObject jsonObject = jsonArray.getJSONObject(i);
            String uuid = (String) list.get(i);
            String fileId = jsonObject.getString(uuid);
            fileIdList.add(fileId);
        }
        List<FileDto> listFileIds = fileInfoFacade.getListFileIds(fileIdList, expireTimeInSecond);
        List<UploadTaskCenterVO> uploadTaskCenterVOS = BeanUtil.mapList(listFileIds, UploadTaskCenterVO.class);
        return uploadTaskCenterVOS;
    }
public List<ButtonConfigDeviceVO> listDeviceType(String code) {
        JSONArray jsonArray = JSON.parseArray(dataListenerConfiguration.getButtonCategory());
        for (int i = 0; i < jsonArray.size(); i++) {
            JSONObject jsonObject = jsonArray.getJSONObject(i);
            if (jsonObject.getString("code").equalsIgnoreCase(code)) {
                return GtsBeanUtils.copyListProperties(jsonObject.getJSONArray("deviceType"), ButtonConfigDeviceVO::new, (s, t) -> {
                    t.setCategoryCode(code);
                }, "deviceModels");
            }
        }
        return Collections.emptyList();
    }
 public List<String> listDeviceModel(String code, String thingModel) {
        JSONArray jsonArray = JSON.parseArray(dataListenerConfiguration.getButtonCategory());
        for (int i = 0; i < jsonArray.size(); i++) {
            JSONObject jsonObject = jsonArray.getJSONObject(i);
            if (jsonObject.getString("code").equalsIgnoreCase(code)) {
                JSONArray jsonArray1 = jsonObject.getJSONArray("deviceType");
                for (int i1 = 0; i1 < jsonArray1.size(); i1++) {
                    JSONObject jsonObject1 = jsonArray1.getJSONObject(i1);
                    if (jsonObject1.getString("thingModel").equalsIgnoreCase(thingModel)) {
                        return JSON.parseArray(jsonObject1.getJSONArray("deviceModels").toJSONString(), String.class);
                    }
                }
            }
        }
        return Collections.emptyList();
    }


    public String getCodeByThingModel(String thingModel) {
        JSONArray jsonArray = JSON.parseArray(dataListenerConfiguration.getButtonCategory());
        for (int i = 0; i < jsonArray.size(); i++) {
            JSONObject jsonObject = jsonArray.getJSONObject(i);
            String code = jsonObject.getString("code");
            JSONArray jsonArray1 = jsonObject.getJSONArray("deviceType");
            for (int i1 = 0; i1 < jsonArray1.size(); i1++) {
                JSONObject jsonObject1 = jsonArray1.getJSONObject(i1);
                List<String> deviceModels = JSON.parseArray(jsonObject1.getJSONArray("deviceModels").toJSONString(), String.class);
                for (String deviceModel : deviceModels) {
                    if (thingModel.equalsIgnoreCase(deviceModel)) {
                        return code;
                    }
                }
            }
        }
        return "smartSwitch";
    }
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值