I convert json string to JSONObject using JSONObject jsonObject = new JSONObject(jsonString);
And the convert jsonObject to Java Object using gson
But it gives an error when a json attribute value contains quotes,
like , { "length" : "10"" } (its, 10 inches)
Edit :
i get data from server api in following manner :
"{\"data\":\"10\"\"}"
i replace \"
by "
, and which converts into { "data" : "10"" }
this gives exception as it cannot convert jsonobject into java object
org.json.JSONException: Unterminated object at character 13 of {"data":"10""}
How can i convert "{\"data\":\"10\"\"}"
to { "data" : "10\"" }
Edit 2 :
I was converting the string to JSONObject the wrong way.
By removing slashes, I was also removing the slashes of escaped characters.
Solution : Instead, I used StringEscapeUtils.unescapeJson(jsonString) which didn't remove the slashes of escaped characters inside json key-value data.