Back

Explore Courses Blog Tutorials Interview Questions
+7 votes
3 views
in Python by (850 points)
edited by

How do I convert a string variable jsonString into JSON object? Please help.
 

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

2 Answers

+11 votes
by (10.5k points)
edited by
  • If you want to convert a string into a JSON object, try using GSON.

GSON g= new GSON();

  • You can also use the org.json library:

try {
     JSONObject jsonObject = new JSONObject("{\"phonetype\":\"N95\",\"dog\":\"WP\"}");
}catch (JSONException err){
     Log.d("Error", err.toString());
}

0 votes
by (106k points)

You can use the below-mentioned code:-

JSONParser parser = new JSONParser();

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

You can use the following video tutorials to clear all your doubts:-

Related questions

0 votes
2 answers
0 votes
1 answer
0 votes
1 answer
asked Aug 15, 2019 in Java by Krishna (2.6k points)
0 votes
1 answer
0 votes
1 answer
asked Nov 12, 2019 in Java by Anvi (10.2k points)

Browse Categories

...