I want to convert a string into a JSON Array using the json-simple-1.1.1.jar
library and came up with the following code,
import org.json.simple.*;
What am I doing wrong here?
You're trying to convert a String
that contains a JSON array into a JSONObject
JSONObject jsonObject = new JSONObject(output);
Your content represents a JSON array so parse it as such
JSONParser parser = new JSONParser();
JSONArray jsonArray = (JSONArray) parser.parse(output);
Note that other libraries, like Gson and Jackson, have much better abstractions for JSON arrays and objects (JsonArray
, ArrayNode
). Consider using those instead.