Skip to content Skip to sidebar Skip to footer

Android: Parsing Json String Inside Of Double Quotes

I am normally using the following code to parse JSON strings: JSONObject jobj = new JSONObject(message); strmsg = jobj.getString('text'); when the data is like the below, it works

Solution 1:

to trim double quotes from both sides:

strmsg.replaceAll("^\"|\"$", "")

Solution 2:

This seems to be an error in the JSON generation. JSON should indeed throw a parse error here. If you cannot change the way, the JSON string is generated, you need to clean it up manually. Remove the quotes around the curly braces and deescape the quotes (you could do it by simplay calling jsonString.replace("\\"", "\""); while this looks convoluted, the escaping is necessary...

String test ="\"{\\\"emailAddress\\\":\\\"testuser@gmail.com\\\"}\"";
test.replace("\\\"", "\"");

Post a Comment for "Android: Parsing Json String Inside Of Double Quotes"