0 votes
1 view
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 (46.1k 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 (28.1k 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
0 votes
1 answer
0 votes
1 answer
asked Aug 15 in Java by Krishna (2.6k points)
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...