Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (3.9k points)

I have String variable called jsonString:

{"phonetype":"N95","cat":"WP"}

Now I want to convert it into JSON Object. I searched more on Google but didn't get any expected answers...

2 Answers

0 votes
by (46k points)

Try org.json library:

try {

     JSONObject jsonObject = new JSONObject("{\"phonetype\":\"N95\",\"cat\":\"WP\"}");

}catch (JSONException err){

     Log.d("Error", err.toString());

}

0 votes
by (32.3k points)

You can also try this:

JSONParser parser = new JSONParser();

JSONObject json = (JSONObject) parser.parse(stringToParse);

Related questions

+7 votes
2 answers
0 votes
1 answer
asked Aug 15, 2019 in Java by Krishna (2.6k points)
0 votes
1 answer
asked Jul 10, 2019 in Java by Ritik (3.5k points)
0 votes
1 answer
0 votes
1 answer

Browse Categories

...