Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/397.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
Java 使用base64编码groovy变量_Java_Groovy - Fatal编程技术网

Java 使用base64编码groovy变量

Java 使用base64编码groovy变量,java,groovy,Java,Groovy,我有一个这样的字符串,我正试图用base64编码这个字符串 {"htmlBrowserType":"Default","mimeType":"text/html","url":"https://github.comcast.com"} String base64Config = {"htmlBrowserType\":\"Default\",\"mimeType\":\"text/html\",\"url\":\"https://github.comcast.com"} 实际上它是一个g

我有一个这样的字符串,我正试图用base64编码这个字符串

{"htmlBrowserType":"Default","mimeType":"text/html","url":"https://github.comcast.com"}

String base64Config =   {"htmlBrowserType\":\"Default\",\"mimeType\":\"text/html\",\"url\":\"https://github.comcast.com"}
实际上它是一个groovy代码

    def encoded = base64Config.bytes.encodeBase64().toString()
使用工具进行编码时,我得到

eyJodG1sQnJvd3NlclR5cGUiOiJEZWZhdWx0IiwibWltZVR5cGUiOiJ0ZXh0L2h0bWwiLCJ1cmwiOiJodHRwczovL2dpdGh1Yi5jb21jYXN0LmNvbSJ9
但是它不能用java代码工作,而我解码的字符串得到的结果是上面的java代码不是

{"htmlBrowserType":"Default","mimeType":"text/html","url":"https://github.comcast.com"}

您的
base64Config
不是字符串,而是闭包:

String base64Config = {"htmlBrowserType\":\"Default\",\"mimeType\":\"text/html\",\"url\":\"https://github.comcast.com"}
应该是:

String base64Config = "{\"htmlBrowserType\":\"Default\",\"mimeType\":\"text/html\",\"url\":\"https://github.comcast.com\"}"

您使用什么Java代码来解码字符串?你给我们看的只是故事的一半。您得到的输出是什么?当我解码输出时,我得到的是'com.uegGlue$\u base64\u configuration\u生成的\u带有\u url\u参数\u设置为\u_closure1@23c1e787'您要编码的Groovy代码看起来不错,但我们需要查看您用来解码的代码。我猜这就是问题所在。我总是更喜欢
{“htmlBrowserType”:“Default”,“mimeType”:“text/html”,“url”:https://github.comcast.com“}”
所以您不需要escaping@tim_yates是的,我同意