I am getting an inputstream and converting it to String
and then to JSONObject
Below is snippet for converting inputstream to String and then JSONObject.
But after converting to json object(line 6) I am getting only the first object
instead of all the objects
Can you please let me know why I am getting only one object instead of all the n objects
InputStream in = new BufferedInputStream(conn.getInputStream());
String result = org.apache.commons.io.IOUtils.toString(in, "UTF-8");
int i =result.indexOf("{");
String forResult=result.substring(i);
System.out.println(forResult); // Result 1
JSONObject jsonObject = new JSONObject(forResult); // Line 6
System.out.println(jsonObject); // Result 2
After converting it to String it look like this
Result -1
{
"test_expr":"",
"val_expr":"someVale",
"val_advanced":true,
"machine_val":null
}, {...// n times}
Result-2 -only first object
{
"test_expr":"",
"val_expr":"someVale",
"val_advanced":true,
"machine_val":null
}
Thanks and please bear my ignorance as I am completly new in java