I'm new in Java and I'm creating a web app using Servlet in Eclipse. I want to convert string to JSON using this code :
import org.json.JSONException;
import org.json.JSONObject;
JSONObject jsonObject = null;
jsonObject = new JSONObject(STRING);
System.out.println(jsonObject.getString("PROPERTY_NAME"));
It works fine if STRING
be equal to "{'status':0}"
and jsonObject.getString("status")
gives me 0
.
But I get a response from API like "{"status":0}"
and jsonObject.getString("status")
gives me error because jsonObject
is :
{}
And the error is :
org.json.JSONException: JSONObject["status"] not found.
Do you have any solution about this?