How to escape the quotes in JSON Object?

后端 未结 4 1469
予麋鹿
予麋鹿 2021-01-19 17:31

Below is my method which makes the JSONObject and then print out the JSONString.

I am using Google GSON.

private String gen         


        
4条回答
  •  星月不相逢
    2021-01-19 18:13

    Use StringEscapeUtils:

    import org.apache.commons.lang3.StringEscapeUtils;
    
    (...)
    
    myString = StringEscapeUtils.escapeJson(myString);
    

    On Android, remember to update your app/build.gradle:

    compile 'org.apache.commons:commons-lang3:3.4'
    

提交回复
热议问题