I am trying to call the REST API of my web service. It is a synchronous call and in response I expect a Json Array of some Object. For ex :-
[{"firstName":"John", "lastName":"Doe"}, {"firstName":"Anna", "lastName":"Smith"}, {"firstName":"Peter","lastName":"Jones"}]
The response is being read by me is using somthing like below -
InputStream in = address.openStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
StringBuilder result = new StringBuilder();
String line;
while((line = reader.readLine()) != null) {
result.append(line);
}
System.out.println(result.toString());
Now the problem statement is - I am getting a json like this -
!!com.company.Employee {"firstName":"John", "lastName":"Doe"}, !!com.company.Employee {"firstName":"Anna", "lastName":"Smith"}, !!com.company.Employee {"firstName":"Peter","lastName":"Jones"}
So when I try to pass this string in my JSONArray's constructor it is throwing Exception.
JSONArray jsonArray = new JSONArray(responseJsonString);
The exception is invalid json array it should start with "["
How this can be solved? Kindly share your views, I've already spent 3 hours on it.