HiveBrain v1.2.0
Get Started
← Back to all entries
snippetjavaCritical

How to convert jsonString to JSONObject in Java

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
jsonobjecthowjavaconvertjsonstring

Problem

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!

Solution

Using org.json library:

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

Code Snippets

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

Context

Stack Overflow Q#5245840, score: 863

Revisions (0)

No revisions yet.