为什么Groovy JSONBuilder在网址中跳过斜杠? [英] Why does the Groovy JSONBuilder escape slashes in URLs?
问题描述
我正在编写一个需要将JSON POST到一个URL的Groovy脚本。我注意到一个问题是,我的JSON中包含'/'的所有元素都被JSON Builder更改为'\ /'。有没有办法阻止它?
这是使用Groovy 1.8。这里有一个简单的例子和它的输出:
$ pre $ def $ json = new JsonBuilder()
json.reply {
结果'http://google.ie/testing'
}
println json.toString()
输出 - > {reply:{result:http:\ / \ / google.ie\ / testing}}
谢谢
刚刚看了一下, groovy.json。 JsonOuput.toJson(string)
将正斜杠编码为'\\ /'
。
您可以使用 toPrettyString
,但它不会这样做:
def json = new groovy.json.JsonBuilder()
json.reply {
结果'http://google.ie/testing'
}
assert json.toPrettyString()=='''{
reply:{
result:http://google.ie/testing
}
}'''
I am writing a Groovy script that needs to POST JSON to a URL. I have noticed a problem were all elements in my JSON that contains a '/' are changed to '\/' by the JSON Builder. Is there a way to stop this?
This is using Groovy 1.8. Here is a simple example and its output:
def json = new JsonBuilder()
json.reply {
result 'http://google.ie/testing'
}
println json.toString()
Output -> {"reply":{"result":"http:\/\/google.ie\/testing"}}
Thanks
Just had a look, and groovy.json.JsonOuput.toJson(string)
encodes forward slash as '\\/'
.
You can use toPrettyString
and it doesn't do it however:
def json = new groovy.json.JsonBuilder()
json.reply {
result 'http://google.ie/testing'
}
assert json.toPrettyString() == '''{
"reply": {
"result": "http://google.ie/testing"
}
}'''
这篇关于为什么Groovy JSONBuilder在网址中跳过斜杠?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!