JSON, replace quotes and slashes, but by what?

后端 未结 4 797
礼貌的吻别
礼貌的吻别 2021-01-19 18:49

I have the ungrateful task to build a JSON String in Java, manually, without any framework, just a StringBuilder. I know this is bad, but it is only part of a prototype, I w

4条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-19 19:09

    "\"Some text WITH quotes\", slashes: /foo and backslashes \\foo"
    

    translates to:

    "Some text WITH quotes", slashes: /foo and backslashes \foo
    

    You can use StringEscapeUtils.escapeJavaScript() in apache-commons Lang 2.6 or StringEscapeUtils.escapeEcmaScript() in 3.4 to do the hard-work of escaping for you.

提交回复
热议问题