1 回答

TA貢獻(xiàn)1829條經(jīng)驗(yàn) 獲得超13個(gè)贊
好吧,它現(xiàn)在只是在進(jìn)行中,但這應(yīng)該可以解決只有一個(gè)數(shù)組的字符串。將研究使其更穩(wěn)定并能夠處理更復(fù)雜的結(jié)構(gòu)。
private static String reformat(String og){
String reformattable = og;
String[] parts = reformattable.split("\\[",2);
String arrayPart = parts[1];
String arrayOnly = arrayPart.split("]",2)[0];
reformattable = arrayOnly.replaceAll("\\{\n","{");
reformattable = reformattable.replaceAll("\",\n", "\\\",");
reformattable = reformattable.replaceAll(" +"," ");
reformattable = reformattable.replaceAll("\\{ "," {");
reformattable = reformattable.replaceAll("\n }","}");
return og.replace(arrayOnly,reformattable);
}
結(jié)果應(yīng)該是這樣的(至少對(duì)于我的簡(jiǎn)單類):
{
"classname": "test",
"properties": [
{"propertyname": "1", "length": 1},
{"propertyname": "1", "length": 1}
]
}
添加回答
舉報(bào)