如果被字符包围,则嵌入式表达式不会被替换 [英] Embedded expressions not replaced if surrounded by characters
本文介绍了如果被字符包围,则嵌入式表达式不会被替换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在以下简化且非常基本的情况下,嵌入的表达式在用字符附加,前置或包围时不会被替换:
The embedded expressions are not replaced when appended, prepended or surrounded by characters in the following simplified and very basic scenario:
* def jobId = '0001'
* def out =
"""
{
"jobId": "#(jobId)",
"outputMetadata": {
"fileName_OK": "#(jobId)",
"fileName_Fail_1": "some_text_#(jobId)",
"fileName_Fail_2": "#(jobId)-and-some-more-text",
"fileName_Fail_3": "prepend #(jobId) and append"
}
}
"""
* print out
执行该方案将返回:
{
"jobId": "0001",
"outputMetadata": {
"fileName_OK": "0001",
"fileName_Fail_1": "some_text_#(jobId)",
"fileName_Fail_2": "#(jobId)-and-some-more-text",
"fileName_Fail_3": "prepend #(jobId) and append"
}
}
是功能,限制还是错误?或者,我错过了什么吗?
Is it a feature, a limitation, or a bug? Or, did I miss something?
推荐答案
这是设计好的!您可以这样做:
This is as designed ! You can do this:
"fileName_Fail_2": "#(jobId + '-and-some-more-text')"
任何有效的JS表达式都可以填充到嵌入式表达式中,因此这不是一个限制.而且这仅在JSON字符串值内或整个RHS是带引号的字符串时起作用,并且使解析变得简单.希望能有所帮助!
Any valid JS expression can be stuffed into an embedded expression, so this is not a limitation. And this works only within JSON string values or when the entire RHS is a string within quotes and keeps the parsing simple. Hope that helps !
这篇关于如果被字符包围,则嵌入式表达式不会被替换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文