diff --git a/intc-modules/intc-iot/src/main/java/com/intc/iot/handler/DeviceDataHandler.java b/intc-modules/intc-iot/src/main/java/com/intc/iot/handler/DeviceDataHandler.java index 802b3f0..ef49ed2 100644 --- a/intc-modules/intc-iot/src/main/java/com/intc/iot/handler/DeviceDataHandler.java +++ b/intc-modules/intc-iot/src/main/java/com/intc/iot/handler/DeviceDataHandler.java @@ -188,8 +188,12 @@ public class DeviceDataHandler { try { JSONObject data = new JSONObject(payload, JSONConfig.create().setIgnoreCase(false)); - // 解析飞燕平台消息格式 - JSONObject params = data.getJSONObject("params"); + // 解析飞燕平台消息格式(保持ignoreCase=false,避免子对象丢失大小写配置) + JSONObject params = null; + Object paramsObj = data.get("params"); + if (paramsObj != null) { + params = new JSONObject(paramsObj.toString(), JSONConfig.create().setIgnoreCase(false)); + } // 从Topic中解析产品Key和设备名称 // Topic格式: /sys/{ProductKey}/{DeviceName}/thing/event/property/post @@ -299,7 +303,12 @@ public class DeviceDataHandler { try { JSONObject data = new JSONObject(payload, JSONConfig.create().setIgnoreCase(false)); - JSONObject params = data.getJSONObject("params"); + // 保持ignoreCase=false,避免子对象丢失大小写配置 + JSONObject params = null; + Object paramsObj = data.get("params"); + if (paramsObj != null) { + params = new JSONObject(paramsObj.toString(), JSONConfig.create().setIgnoreCase(false)); + } // 从Topic中解析产品Key、设备名称和事件标识符 // Topic格式: /sys/{ProductKey}/{DeviceName}/thing/event/{EventIdentifier}/post @@ -2119,6 +2128,8 @@ public class DeviceDataHandler { : params.getDouble("ph"); sensorData.setPh(value); } + // 注意:忽略大小写时 containsKey("salinity") 会误匹配 salinitySet, + // 已在取 params 时设置 ignoreCase=false,精确匹配 "salinity" key,不会取到 salinitySet if (params.containsKey("salinity")) { sensorData.setSalinity(params.getDouble("salinity")); }