直接上代码
public static JSONObject analysisJSON(JSONObject jsonObj, JSONObject result, String key) {
Set<String> rootKeys = jsonObj.keySet();
for (String rootKey : rootKeys) {
Object subData = jsonObj.get(rootKey);
if (subData instanceof JSONObject) {
if (key == null) {
analysisJSON((JSONObject) subData, result, rootKey);
} else {
analysisJSON((JSONObject) subData, result, key + "." + rootKey);
}
} else {
if (key == null) {
result.put(rootKey, subData);
} else {
result.put(key + "." + rootKey, subData);
}
}
}
return result;
}
调用
DataUtils.analysisJSON(jsonObj, new JSONObject(), null)