[Solved] Convert string of valid JSON to JSON object in Java, so I can index into it


You are trimming the string and turning it into an invalid JSON.

Your JSON starts with a “[” that indicates it is an array. If it starts with “{” you can assume that is an object.

So, as your JSON is an array, you can parse this exact content you mentioned with:

JSONArray jsonArray = new JSONArray(string);

And access the elements like in a List:

jsonArray.get(0);

10

solved Convert string of valid JSON to JSON object in Java, so I can index into it