I have a one string but it contain two object like {"firstName":"A","lastName":"Z"}{"firstName":"B","lastName":"Y"}
i got this String as a response but i want to process it differantly one by one, so how i seprate this one like {"firstName":"A","lastName":"Z"} and {"firstName":"B","lastName":"Y"}Separatly
>Solution :
Object mapper = new ObjectMapper();
List<YourClass> ls= ((ObjectMapper) mapper).readValue(
"[{"firstName":"A","lastName":"Z"},{"firstName":"B","lastName":"Y"}]",
new TypeReference<List<YourClass>>() {
});
//process list.
YourClass is mapping class of json input. Hope this is what you are looking for.
Edit:
As your input is received in {"firstName":"A","lastName":"Z"}{"firstName":"B","lastName":"Y"} fashion, then
String input=" {"firstName":"A","lastName":"Z"}{"firstName":"B","lastName":"Y"}";
String array[]=a.split("(?=\\{)|(?<=\\})");
System.out.println(array[0]);
System.out.println(array[1]);
Output:
{"firstName":"A","lastName":"Z"}
{"firstName":"B","lastName":"Y"}