Merge pull request #4460 from dataease/pr@dev@pages

fix: 解析API数据出错
This commit is contained in:
taojinlong 2023-02-06 16:23:22 +08:00 committed by GitHub
commit 6ba4e8fe46
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -266,13 +266,11 @@ public class ApiProvider extends Provider {
for (String s : jsonObject.keySet()) {
String value = jsonObject.getString(s);
if (StringUtils.isNotEmpty(value) && value.startsWith("[")) {
JSONObject o = new JSONObject();
try {
JSONArray jsonArray = jsonObject.getJSONArray(s);
List<JSONObject> childrenField = new ArrayList<>();
for (Object object : jsonArray) {
JSONObject.parseObject(object.toString());
handleStr(apiDefinition, JSON.toJSONString(object, SerializerFeature.WriteMapNullValue), childrenField, rootPath + "." + s + "[*]");
}
o.put("children", childrenField);
@ -289,15 +287,28 @@ public class ApiProvider extends Provider {
fields.add(o);
}
} else if (StringUtils.isNotEmpty(value) && value.startsWith("{")) {
List<JSONObject> children = new ArrayList<>();
handleStr(apiDefinition, jsonObject.getString(s), children, rootPath + "." + String.format(path, s));
JSONObject o = new JSONObject();
o.put("children", children);
o.put("childrenDataType", "OBJECT");
o.put("jsonPath", rootPath + "." + s);
setProperty(apiDefinition, o, s);
if (!hasItem(apiDefinition, fields, o)) {
fields.add(o);
try {
JSONObject.parseObject(jsonStr);
List<JSONObject> children = new ArrayList<>();
handleStr(apiDefinition, jsonObject.getString(s), children, rootPath + "." + String.format(path, s));
JSONObject o = new JSONObject();
o.put("children", children);
o.put("childrenDataType", "OBJECT");
o.put("jsonPath", rootPath + "." + s);
setProperty(apiDefinition, o, s);
if (!hasItem(apiDefinition, fields, o)) {
fields.add(o);
}
}catch (Exception e){
JSONObject o = new JSONObject();
o.put("jsonPath", rootPath + "." + String.format(path, s));
setProperty(apiDefinition, o, s);
JSONArray array = new JSONArray();
array.add(StringUtils.isNotEmpty(jsonObject.getString(s)) ? jsonObject.getString(s) : "");
o.put("value", array);
if (!hasItem(apiDefinition, fields, o)) {
fields.add(o);
}
}
} else {
JSONObject o = new JSONObject();
@ -325,13 +336,13 @@ public class ApiProvider extends Provider {
o.put("deType", 0);
o.put("extField", 0);
o.put("checked", false);
for (DatasetTableFieldDTO fieldDTO : apiDefinition.getFields()) {
if (StringUtils.isNotEmpty(o.getString("jsonPath")) && StringUtils.isNotEmpty(fieldDTO.getJsonPath()) && fieldDTO.getJsonPath().equals(o.getString("jsonPath"))) {
o.put("checked", true);
o.put("deExtractType", fieldDTO.getDeExtractType());
o.put("name", fieldDTO.getName());
}
}
// for (DatasetTableFieldDTO fieldDTO : apiDefinition.getFields()) {
// if (StringUtils.isNotEmpty(o.getString("jsonPath")) && StringUtils.isNotEmpty(fieldDTO.getJsonPath()) && fieldDTO.getJsonPath().equals(o.getString("jsonPath"))) {
// o.put("checked", true);
// o.put("deExtractType", fieldDTO.getDeExtractType());
// o.put("name", fieldDTO.getName());
// }
// }
}