parent
420390f454
commit
30fba73f72
|
@ -205,12 +205,12 @@ public class ApiMappingBillPlugin extends AbstractFormPlugin implements Plugin {
|
|||
}
|
||||
}
|
||||
jsonArray.add(json);
|
||||
codeEdit.setText(jsonArray.toJSONString());
|
||||
codeEdit.setText(format(jsonArray.toJSONString()));
|
||||
logger.info("数组 → JSON:{}", jsonArray.toJSONString());
|
||||
} else {
|
||||
JSONObject resultJson = new JSONObject();
|
||||
processFloor(resultJson, "data", floors.get(0), floors, billObject);
|
||||
codeEdit.setText(resultJson.toJSONString());
|
||||
codeEdit.setText(format(resultJson.toJSONString()));
|
||||
logger.info("对象 → JSON:{}", resultJson.toJSONString());
|
||||
}
|
||||
}
|
||||
|
@ -485,4 +485,45 @@ public class ApiMappingBillPlugin extends AbstractFormPlugin implements Plugin {
|
|||
this.getModel().setValue("shkd_defaultdata", def, dynamicObjectCollection.size() - 1);
|
||||
this.getModel().setValue("shkd_parentfield", pKey, dynamicObjectCollection.size() - 1);
|
||||
}
|
||||
|
||||
public String format(String jsonString) {
|
||||
StringBuilder prettyJson = new StringBuilder();
|
||||
char[] chars = jsonString.toCharArray();
|
||||
int indentLevel = 0;
|
||||
|
||||
for (char ch : chars) {
|
||||
switch (ch) {
|
||||
case '{':
|
||||
case '[':
|
||||
prettyJson.append(ch);
|
||||
prettyJson.append('\n');
|
||||
indentLevel++;
|
||||
addIndent(prettyJson, indentLevel);
|
||||
break;
|
||||
case '}':
|
||||
case ']':
|
||||
prettyJson.append('\n');
|
||||
indentLevel--;
|
||||
addIndent(prettyJson, indentLevel);
|
||||
prettyJson.append(ch);
|
||||
break;
|
||||
case ',':
|
||||
prettyJson.append(ch);
|
||||
prettyJson.append('\n');
|
||||
addIndent(prettyJson, indentLevel);
|
||||
break;
|
||||
default:
|
||||
prettyJson.append(ch);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return prettyJson.toString();
|
||||
}
|
||||
|
||||
private void addIndent(StringBuilder sb, int indentLevel) {
|
||||
for (int i = 0; i < indentLevel; i++) {
|
||||
sb.append(" "); // 使用4个空格作为缩进
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue