我有一个看起来像的字符串:
text = " "12.10 On-Going Submission of ""Made Up"" Samples." "
我试图逃避双引号。我尝试了以下的事情:
import groovy.json.StringEscapeUtils;
textFinal: escapeJava(text)
顺便说一句,这篇文章将成为JSON的回应。我收到以下错误作为JSON响应
groovy.lang.MissingMethodException: No signature of method: com.thomsonreuters.ald.aeandsdx.ArtifactController.escapeJava() is applicable for argument types: (java.lang.String) values: ["12.10 On-Going Submission of ""Made Up"" Samples."]{"status":"Bad request","msg":{"arguments":["\"12.10 On-Going Submission of\"\"
控制台上的我收到此错误:
2014-09-25 14:55:07,555 [http-bio-8080-exec-1] ERROR errors.GrailsExceptionResolver - StringIndexOutOfBoundsException occurred when processing request: [GET] /artifact - parameters:
documentName: ICENSE AGREEMENT6
String index out of range: -25. Stacktrace follows:
Message: String index out of range: -25
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 ''
| 134 | render in ''
| 150 | render . . . . in ''
| 328 | $tt__index in com.thomsonreuters.ald.aeandsdx.ArtifactController
| 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
不知道为什么这不起作用。这应该。为了更清楚地了解我想要做什么,请参考Question 1 Question 2和 Question 3
答案 0 :(得分:0)
目前您只是以常规方式导入StringEscapeUtils
,但之后您没有明确地从正确的类中调用该方法。
我怀疑你要么:
import static groovy.json.StringEscapeUtils.escapeJava;
textFinal: escapeJava(text)
或:
import groovy.json.StringEscapeUtils;
textFinal: StringEscapeUtils.escapeJava(text)