Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting string to json object using json.simple

Tags:

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?

like image 611
Talib Avatar asked Jun 10 '15 13:06

Talib


People also ask

How do I convert a string to JSON?

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.

How do you convert a string to a JSON object in Python?

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.

Can we convert string to object in Java?

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.

What is JSON simple?

JSON.simple is a simple Java library for JSON processing, read and write JSON data and full compliance with JSON specification (RFC4627)


1 Answers

Try this:

JSONParser parser = new JSONParser();
JSONObject json = (JSONObject) parser.parse(stringToParse);
like image 96
Shailesh Yadav Avatar answered Oct 19 '22 18:10

Shailesh Yadav