I am sending API call to a service that return a json array like this :
[Object, Object ....]
via my java http request. the resulat are stored in a string:
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
I need to find a way to split this string to by json objects so each new string will contain only one object.
Thanks.
Instead of using the split function, you can convert your String to a JSONArray and then iterate throw the array
JSONArray jsonArray = new JSONArray(response.toString());
for(int i=0; i<jsonArray.length(); i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i);
String jsonObjectAsString = jsonObject.toString();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With