我有一个这样的字符串:
String s = "{"Player":{"id":"1","name":"PM001"}},{"Player":{"id":"2","name":"PM002"}}"
我想省略“,”所以结果应该是:
{"Player":{"id":"1","name":"PM001"}}
{"Player":{"id":"2","name":"PM002"}}
答案 0 :(得分:3)
JSONArray newArray = new JSONArray(s);
newArray.get(0);
newArray.get(1);
答案 1 :(得分:1)
我会在一个用反向花括号包围的逗号上拆分:
String[] parts = s.split("(?<=}),(?=\\{)");
这使用环绕声断言大括号的存在但不消耗。