JSON 文件jsonExample
:
{
"store": {
"book": [
{
"category": "fiction",
"author": "Evelyn Waugh",
"title": "Sword of Honour",
"something": 12.99
}
],
"bicycle": {
"color": "red",
"price": 19.95
}
},
"expensive": 10
}
我要更新"something"
。当我使用时:
1) * set jsonExample $.store.book[0].something = 13
- 这是工作
2) * set jsonExample $..book[0].something = 13
- 这是工作
3) * eval jsonExample.store.book[0].something = 13
- 这是工作
BUT
1) * set jsonExample $..something = 13
- 这是NOT working
2) * eval jsonExample..something = 13
- 这是NOT working
我明白那个set
不适用于通配符($[*].foo
or $..foo
)。但是通配符可以与 eval 一起使用吗?如果是,怎么办?请根据文件举例jsonExample
above.
我不明白你为什么这么关心这个。通配符不适用于updatingJSON。就是这么简单。
还有一件事情,eval
仅适用于纯 JS。 Json 路径是NOT纯JS。
也许这会解释得更清楚。
If * set jsonExample $..book[0].something = 13
正在运行,请假定这是一个 BUG。不要依赖它。在这种情况下它可能会起作用,因为代码尽可能具有弹性。但它可能不适用于其他情况或未来版本的空手道。
以下所有内容都将起作用:
* def jsonExample =
"""
{
"store": {
"book": [
{
"category": "fiction",
"author": "Evelyn Waugh",
"title": "Sword of Honour",
"something": 12.99
}
],
"bicycle": {
"color": "red",
"price": 19.95
}
},
"expensive": 10
}
"""
# all these will work
* set jsonExample $.store.book[0].something = 13
* match jsonExample.store.book[0].something == 13
* set jsonExample.store.book[0].something = 14
* match jsonExample.store.book[0].something == 14
* eval jsonExample.store.book[0].something = 15
* match jsonExample.store.book[0].something == 15
我真的希望这能说明白!
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)