Groovyspect() 处理美元符号($)
下面的代码无法运行
def map = [name:"Test :: ( %2f %25 \$ * & ! @ # ^)"]
String s = map.inspect()
println Eval.me(s)
得到错误:
Script1.groovy: 1: illegal string body character after dollar sign;
solution: either escape a literal dollar sign "\$5" or bracket the value expression "${5}" @ line 1, column 30.
["name":"Test :: ( %2f %25 $ * & ! @ # ^)"]
但如果字符串包含其他特殊字符,如\“,它可以正常工作。无论如何,如何走动?这对我来说很紧急
below code can not run
def map = [name:"Test :: ( %2f %25 \$ * & ! @ # ^)"]
String s = map.inspect()
println Eval.me(s)
get error:
Script1.groovy: 1: illegal string body character after dollar sign;
solution: either escape a literal dollar sign "\$5" or bracket the value expression "${5}" @ line 1, column 30.
["name":"Test :: ( %2f %25 $ * & ! @ # ^)"]
but if string contain other special char like \", it works correctly. any way, how to walk around? it's emergency for me
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
(回应上面的后续)
好的,如果您只是想交换信息,那么您应该使用数据交换格式,例如 XML 或 JSON。我推荐 JSON,因为它轻量、快速且确实易于使用:
计算机 1
计算机 2
请注意,这些需要 Groovy 1.8.0 或功能较新。对于旧版本的 Groovy 有很多示例,Grails 也有自己的内置解析器。
(In response to follow up above)
OK, if you just want to exchange information, then you should use a Data Interchange Format, such as XML or JSON. I recommend JSON because it's lightweight, fast, and really easy to use:
Computer 1
Computer 2
Please note that these require Groovy 1.8.0 or newer to function. There are plenty of examples for older versions of Groovy, and Grails has it's own parsers built-in as well.
在字符串周围使用单引号:
当您使用双引号时,美元字符用于模板化
Use single quotes round your string:
When you use double quotes, the dollar char is used for templating
使用单引号和双反斜杠,例如,
Use single quotes and a double backslash ,like,
我刚刚测试了以下内容,它对我有用
I just tested the following and it worked for me