If your objects are no more complicated than you show, you can use the images as follows:
String[] strs = str.split("(?<=\\})(?=\\{)");
Example:
String str = "{id:\"123\",name:\"myName\"}{id:\"456\",name:\"yetanotherName\"}{id:\"456\",name:\"anotherName\"}"; String[] strs = str.split("(?<=\\})(?=\\{)"); for (String s : strs) { System.out.println(s); }
prints
{id:"123",name:"myName"} {id:"456",name:"anotherName"} {id:"456",name:"yetanotherName"}
If your objects are more complex, the regex probably won't work, and you have to parse your string.
Denys seguret
source share