Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/372.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
StringEscapeUtils.escapeJava错误无法转义双引号_Java_Json_Grails_Utf 8_Escaping - Fatal编程技术网

StringEscapeUtils.escapeJava错误无法转义双引号

StringEscapeUtils.escapeJava错误无法转义双引号,java,json,grails,utf-8,escaping,Java,Json,Grails,Utf 8,Escaping,我有一个字符串,看起来像: 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

我有一个字符串,看起来像:

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
我不知道为什么这行不通。这应该是。为了更清楚地了解我到底想做什么,请参考

目前,您只是以常规方式导入
StringEscapeUtils
,但没有从正确的类显式调用该方法

我想你要么想要:

import static groovy.json.StringEscapeUtils.escapeJava;
textFinal: escapeJava(text)
或:


我做了后一个,但我的JSON被截断了{“documentName”:“ICENSE AGREEMENT6”,“listOfArtifacts”:[{“type”:“子句”,“artifacts”:[{“documentId”:6951,“documentName”:“ICENSE AGREEMENT6”,“artifactId”:7029,“text”:“\\\\\”12.10正在提交中"@krs:听起来可能只是您的日志记录,或者您的输入被截断。我非常怀疑这与转义部分有关。当您说输入被截断时,控制台上也会出现字符串索引越界错误。好的,我明白了。您所说的是正确的。我确实正确了esacping。我打印了文本和它的完美。12.10正在进行的提交由“样本”组成。但是为什么JSON会变得truncated@krs当前位置我无法知道这一点,但这听起来像是一个不同的问题,你应该在不同的帖子中问这个问题。
import groovy.json.StringEscapeUtils;
textFinal: StringEscapeUtils.escapeJava(text)