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?
String data can be easily converted to JSON using the stringify() function, and also it can be done using eval() , which accepts the JavaScript expression that you will learn about in this guide.
you can turn it into JSON in Python using the json. loads() function. The json. loads() function accepts as input a valid string and converts it to a Python dictionary.
We can also convert the string to an object using the Class. forName() method. Parameter: This method accepts the parameter className which is the Class for which its instance is required.
JSON.simple is a simple Java library for JSON processing, read and write JSON data and full compliance with JSON specification (RFC4627)
Try this:
JSONParser parser = new JSONParser();
JSONObject json = (JSONObject) parser.parse(stringToParse);
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