考虑一下,
的值(value)$RespNode
是
RespJson.seatbid[0].bid[0].price
我正在尝试运行
Eval.me('RespJson', RespJson, "assert $RespNode.toString() == '$aValue'")
但出现错误
[No such property: toString for class: java.lang.String]
当我运行这个时(直接运行,没有 Eval() )
assert RespJson.seatbid[0].bid[0].price.toString()==aValue
运行良好(没有错误)
下面的代码也可以正常工作(没有 toString() )
Eval.me('RespJson', RespJson, "assert $RespNode == '$aValue'")
任何想法,如何使用 Eval()
运行 toString()
谢谢!
最佳答案
$RespNode.toString()
将立即被替换。您必须使用 ${RespNode}.toString()
才能通过 eval 运行它。否则请参阅 @WillP 的答案(respNode.toString
立即评估,并且 toString 不是属性)
def respJson = [seatbid:[[bid:[[price:666.0G]]]]]
def respNode = 'respJson.seatbid[0].bid[0].price'
def aValue = '666.0'
Eval.me('respJson', respJson, "assert ${respNode}.toString() == '$aValue'")
关于java - 在 Eval () 中执行 toString() - Groovy(Gstring 中的方法调用),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26261095/