JSON操作自用笔记

it2026-01-24  7

基操勿6

String json = RestClient.exchange(iotUrl + "/api/tenant/device/product/list", HttpMethod.POST, header, paramStr,String.class); JSONObject jsonData = JSONObject.parseObject(json); JSONArray jsonArray = jsonData.getJSONArray("data"); List<DevicesProductResponseVo> devicesProductResponseVoList = new ArrayList<>(); //循环遍历获取每一个JSON,List<DevicesProductResponseVo> for (int i = 0;i < jsonArray.size();i++){ JSONObject obj = jsonArray.getJSONObject(i); Integer id = Integer.parseInt(obj.getString("id")); String name = obj.getString("name"); String fullName = obj.getString("fullName"); DevicesProductResponseVo devicesProductResponseVo1 = new DevicesProductResponseVo(); devicesProductResponseVo1.setId(id); devicesProductResponseVo1.setName(name); devicesProductResponseVo1.setFullName(fullName); devicesProductResponseVoList.add(devicesProductResponseVo1); }

List< LabelVo >与String转换

List<LabelVo> parameter = new Gson().fromJson(diagramNode.getParameter(), new TypeToken<List<LabelVo>>(){}.getType()); String parameter = new Gson().toJson(runningCurvePostVo.getParameter())
最新回复(0)