I am using org.json.simple.JSONObject.
I want to convert string to Json object.
String value=request.getParameter("savepos");
JSONObject jsonObject = (JSONObject) JSONValue.parse(value);
It doesn't work. Why?
I am using org.json.simple.JSONObject.
I want to convert string to Json object.
String value=request.getParameter("savepos");
JSONObject jsonObject = (JSONObject) JSONValue.parse(value);
It doesn't work. Why?
 
    
     
    
    Try this:
JSONParser parser = new JSONParser();
JSONObject json = (JSONObject) parser.parse(stringToParse);
 
    
     
    
    JSONParser parser = new JSONParser();
JSONObject json = (JSONObject) parser.parse(value);
should do the work.
 
    
    Converting String to Json Object by using org.json.simple.JSONObject
private static JSONObject createJSONObject(String jsonString){
    JSONObject  jsonObject=new JSONObject();
    JSONParser jsonParser=new  JSONParser();
    if ((jsonString != null) && !(jsonString.isEmpty())) {
        try {
            jsonObject=(JSONObject) jsonParser.parse(jsonString);
        } catch (org.json.simple.parser.ParseException e) {
            e.printStackTrace();
        }
    }
    return jsonObject;
}
 
    
    In the newer com.github.cliftonlabs.json_simple the code is the following:
JsonObject obj = Jsoner.deserialize(responseString, new JsonObject());
As documented on the project's API docs
