Android: Parsing JSON string inside of double quotes

前端 未结 2 591
孤独总比滥情好
孤独总比滥情好 2020-12-21 22:49

I am normally using the following code to parse JSON strings:

JSONObject jobj = new JSONObject(message);
strmsg = jobj.getString(\"text\");

相关标签:
2条回答
  • 2020-12-21 23:18

    to trim double quotes from both sides:

    strmsg.replaceAll("^\"|\"$", "")
    
    0 讨论(0)
  • 2020-12-21 23:24

    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("\\\"", "\"");
    
    0 讨论(0)
提交回复
热议问题