1
我有这个数据,我希望能够在每个节点只显示名称和IP:使用XPath排除可能的属性?
{
"virtualservers": [
{
"name": "/partition/name",
"ip": "1.1.1.1",
"port": "80",
"defaultpool": "",
"sslprofile": "None",
"compressionprofile": "/Common/cmpprof",
"persistence": "None",
"irules": [
"/Common/http-to-https"
],
"pools": null,
"sourcexlatetype": "None",
"sourcexlatepool": "None",
"loadbalancer": "MYLB"
},
{
"name": "/partition/name2",
"ip": "2.2.2.2",
"port": "80",
"defaultpool": "",
"sslprofile": "None",
"compressionprofile": "/Common/cmpprof",
"persistence": "None",
"irules": [
"/Common/anotherrule"
],
"pools": null,
"sourcexlatetype": "None",
"sourcexlatepool": "None",
"loadbalancer": "MYLB2"
}
]
}
我周围有点戳,这几乎工程:
//virtualserver[(position() > 0 and position() < 10)]/*[name()="name" or name()="ip"]
[
"/partition/name",
"1.1.1.1",
"/partition/name2",
"2.2.2.2"
]
但我想为了让我的节点信息能够在我的模板中正确地遍历它。理想情况下,结果会是这样的
[
{
"name": "/partition/name",
"ip": "1.1.1.1",
},
{
"name": "/partition/name2",
"ip": "2.2.2.2",
}
]
我使用这个defiantjs所以它可能不是使用XPath完全兼容。欢迎任何建议!
/Patrik
Thak你,非常感谢! – PatrikJ