I am working on an Android application. In my app I have to convert a string to Json Object, then parse the values. I checked for a solution in stackoverflow and found similar issue here link
The solution is like this
`{"phonetype":"N95","cat":"WP"}`
JSONObject jsonObj = new JSONObject("{\"phonetype\":\"N95\",\"cat\":\"WP\"}");
I use the same way in my code . My string is
{"ApiInfo":{"description":"userDetails","status":"success"},"userDetails":{"Name":"somename","userName":"value"},"pendingPushDetails":[]}
string mystring= mystring.replace("\"", "\\\"");
And after replace I got the result as this
{\"ApiInfo\":{\"description\":\"userDetails\",\"status\":\"success\"},\"userDetails\":{\"Name\":\"Sarath Babu\",\"userName\":\"sarath.babu.sarath babu\",\"Token\":\"ZIhvXsZlKCNL6Xj9OPIOOz3FlGta9g\",\"userId\":\"118\"},\"pendingPushDetails\":[]}
when I execute JSONObject jsonObj = new JSONObject(mybizData);
I am getting the below json exception
org.json.JSONException: Expected literal value at character 1 of
Please help me to solve my issue.
You just need the lines of code as below:
Here is the code, and you can decide which
(synchronized)StringBuffer or faster StringBuilder to use.
Benchmark shows StringBuilder is Faster.
Remove the slashes:
To get a JSONObject or JSONArray from a String I've created this class:
Here to get the JSON:
Example:
try this:
May be below is better.