MCPcopy Index your code
hub / github.com/10cks/fofaEX / getValueFromJson

Method getValueFromJson

src/main/java/FofaAPI.java:89–130  ·  view source on GitHub ↗
(JSONObject json, String key)

Source from the content-addressed store, hash-verified

87 }
88
89 public static Object getValueFromJson(JSONObject json, String key) {
90
91 // 首先检查json对象是否为null
92 if (json == null) {
93 return null; // 直接返回null,不进行后续操作
94 }
95
96 Object value = json.opt(key); // 使用opt来避免JSONException
97
98 if (value instanceof JSONArray) {
99 // 如果值是JSONArray,转换为List<List<String>>
100 JSONArray jsonArray = (JSONArray) value;
101 List<List<String>> list = new ArrayList<>();
102 for (int i = 0; i < jsonArray.length(); i++) {
103 JSONArray subArray = jsonArray.optJSONArray(i);
104 if (subArray == null) {
105 continue; // 如果不是JSONArray,则跳过
106 }
107 List<String> subList = new ArrayList<>();
108 for (int j = 0; j < subArray.length(); j++) {
109 subList.add(subArray.optString(j)); // 使用optString来避免JSONException
110 }
111 list.add(subList);
112 }
113 return list;
114 } else if (value instanceof Integer) {
115 // 如果值是Integer,直接返回
116 return (Integer) value;
117 } else if (value instanceof Double) {
118 // 如果值是Double,直接返回
119 return (Double) value;
120 } else if (value instanceof Boolean) {
121 // 如果值是Boolean,直接返回
122 return (Boolean) value;
123 } else if (value instanceof String) {
124 // 如果值是String,直接返回
125 return (String) value;
126 } else {
127 // 如果键不存在或值为null,返回null
128 return null;
129 }
130 }
131
132 public static List<String> getColumn(List<List<String>> matrix, int index) {
133

Callers 1

doInBackgroundMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected