文件/tmp/t
[
{
"name:first" : "trevor",
"last" : "wellington",
"from" : "england",
"age" : 52,
"sports" : [ "rugby", "badmitton", "snooker" ]
},
{
"name:first" : "yoni",
"last" : "halevi",
"from" : "israel",
"age" : 26,
"sports" : [ "soccer", "windsurfing" ]
},
{
"name:first" : "cory",
"last" : "parker",
"from" : "united states",
"age" : 31,
"sports" : [ "windsurfing", "baseball", "extreeeeme kayaking" ]
}
]
这很好用
cat /tmp/t | jsawk -n 'out(this.last)'
但事实并非如此
cat test.json | jsawk -n 'out(this.name:first)'
可能与:
Selecting a JSON object with a colon in the key
和
How do I access these weird JSON items with jQuery?
但是
cat test.json | jsawk -n 'out(this.name[':first'])'
不起作用
答案 0 :(得分:4)
你走了:
... | jsawk -n 'out(this["name:first"])'
this.name:first
不起作用,因为裸:
不能出现在对象属性中。
例如,给定此JavaScript对象:
x = {
"name:first" : "cory",
"last" : "parker",
"from" : "united states",
"age" : 31,
"sports" : [ "windsurfing", "baseball", "extreeeeme kayaking" ]
}
这些是有效的:
x.last
和x['last']
x.from
和x['from']
x['name:first']
(x.name:first
不是)