如何在 Grails 中转义字符串中的双引号:
string = " "12.10 On-Going Submission of ""Made Up"" Samples." "
我尝试了很多方法
//text : artifact.text.encodeAsJavaScript(),
//text: artifact.text.encodeAsHTML(),
//text: StringEscapeUtils.escapeJava((String)artifact.text), //got an error when doing this
//text: artifact.text.replaceAll("\" "," \\\\" "),
以上都不适合我。您可以参考发布的问题来了解我的问题here https://stackoverflow.com/questions/26025673/json-issues-with-rest-api-and-special-characters
and here https://stackoverflow.com/questions/26039819/escape-string-in-grails-to-avoid-json-error too
错误(json 停止于“\\”12.10 正在进行的提交 o\\“\\””):
014-09-25 12:15:21,869 [http-bio-8080-exec-3] ERROR errors.GrailsExceptionResolver - StringIndexOutOfBoundsException occurred when processing request: [GET] /artifact - parameters:
documentName: ICENSE AGREEMENT6
String index out of range: -28. Stacktrace follows:
Message: String index out of range: -28
Line | Method
->> 1911 | substring in java.lang.String
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 1946 | subSequence in ''
| 1042 | append . . . . in java.io.PrintWriter
| 56 | append in ''
| 180 | value . . . . in grails.converters.JSON
| 162 | convertAnother in ''
| 202 | value . . . . in ''
| 162 | convertAnother in ''
| 202 | value . . . . in ''
| 162 | convertAnother in ''
| 202 | value . . . . in ''
| 162 | convertAnother in ''
| 202 | value . . . . in ''
| 162 | convertAnother in ''
| 202 | value . . . . in ''
| 134 | render in ''
| 150 | render . . . . in ''
| 325 | $tt__index in com.thomsonreuters.ald.aeandsdx.ArtifactController$$EOqtIczI
| 198 | doFilter . . . in grails.plugin.cache.web.filter.PageFragmentCachingFilter
| 63 | doFilter in grails.plugin.cache.web.filter.AbstractFilter
| 1145 | runWorker . . in java.util.concurrent.ThreadPoolExecutor
| 615 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run . . . . . in java.lang.Thread
None
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)