我想在字符串下分割
{"address":"XXXXXX","amount":"0.25"},{"address":"AAAAAA","amount":"0.25"}
分为两个值
{"address":"XXXXXX","amount":"0.25"}
{"address":"AAAAAA","amount":"0.25"}
答案 0 :(得分:3)
不建议您按照自己的方式解析json,但是如果您确实想拆分,则可以使用正则表达式使用环视方法来解析。这是相同的Java代码。
public static void main(String args[]) throws Exception {
String s = "{\"address\":\"XXXXXX\",\"amount\":\"0.25\"},{\"address\":\"AAAAAA\",\"amount\":\"0.25\"}";
String[] data = s.split("(?<=\\}),(?=\\{)");
Arrays.asList(data).forEach(System.out::println);
}
打印
{"address":"XXXXXX","amount":"0.25"}
{"address":"AAAAAA","amount":"0.25"}