Browse Source

喇叭问题空指针健壮性处理

hanzhiwei 2 years ago
parent
commit
7fa5594243

+ 2 - 2
zd-modules/zd-algorithm/src/main/java/com/zd/alg/speaker/controller/SpeakerController.java

@@ -73,7 +73,7 @@ public class SpeakerController {
             for(int i=0;i<jsonArray.size();i++){
             for(int i=0;i<jsonArray.size();i++){
                 JSONObject extra=jsonArray.getJSONObject(i).getJSONObject("extra");
                 JSONObject extra=jsonArray.getJSONObject(i).getJSONObject("extra");
                 JSONObject obj = extra.getJSONObject("config");
                 JSONObject obj = extra.getJSONObject("config");
-                if(obj.getString("mac").equals(map.getOrDefault("hardwareNum","").toString())){
+                if(!Objects.isNull(obj) && obj.getString("mac").equals(map.getOrDefault("hardwareNum","").toString())){
                     map.put("deviceSn",obj.getString("sn"));
                     map.put("deviceSn",obj.getString("sn"));
                     map.put("deviceIp",extra.getString("ip"));
                     map.put("deviceIp",extra.getString("ip"));
                     map.put("operate",extra.getString("online"));
                     map.put("operate",extra.getString("online"));
@@ -111,7 +111,7 @@ public class SpeakerController {
             for(int i=0;i<jsonArray.size();i++){
             for(int i=0;i<jsonArray.size();i++){
                 JSONObject extra=jsonArray.getJSONObject(i).getJSONObject("extra");
                 JSONObject extra=jsonArray.getJSONObject(i).getJSONObject("extra");
                 JSONObject obj = extra.getJSONObject("config");
                 JSONObject obj = extra.getJSONObject("config");
-                if(obj.getString("mac").equals(map.getOrDefault("hardwareNum","").toString())){
+                if(!Objects.isNull(obj) && obj.getString("mac").equals(map.getOrDefault("hardwareNum","").toString())){
                     map.put("deviceSn",obj.getString("sn"));
                     map.put("deviceSn",obj.getString("sn"));
                     map.put("deviceIp",extra.getString("ip"));
                     map.put("deviceIp",extra.getString("ip"));
                     map.put("operate",extra.getString("online"));
                     map.put("operate",extra.getString("online"));