How to convert jsonString to JSONObject in Java

Mr. Sajid Shaikh picture Mr. Sajid Shaikh · Mar 9, 2011 · Viewed 1.5M times · Source

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...

Answer

dogbane picture dogbane · Mar 9, 2011

Using org.json library:

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