【发布时间】:2021-06-21 20:14:09
【问题描述】:
使用 jsonpath-plus 模块(打字稿),我试图导航到 json 文档中的特定对象。目标对象向下几级,包括通过 2 级数组。以下jsonpath语句:
$..['gmd:DQ_AbsoluteExternalPositionalAccuracy']
在线jsonpath测试网站jsonpath.com返回如下结果:
[
{
"gmd:nameOfMeasure": {
"gco:CharacterString": "Difference to ICESat LE90"
},
"gmd:result": {
"gmd:DQ_QuantitativeResult": {
"gmd:valueUnit": {
"@xlink:href": "http://www.opengis.net/def/uom/OGC/1.0/metre"
},
"gmd:value": {
"gco:Record": {
"gco:Real": "0.655608"
}
}
}
}
},
{
"gmd:nameOfMeasure": {
"gco:CharacterString": "Difference to ICESat Vertical Mean"
},
"gmd:result": {
"gmd:DQ_QuantitativeResult": {
"gmd:valueUnit": {
"@xlink:href": "http://www.opengis.net/def/uom/OGC/1.0/metre"
},
"gmd:value": {
"gco:Record": {
"gco:Real": "-0.005536"
}
}
}
}
},
{
"gmd:nameOfMeasure": {
"gco:CharacterString": "Difference to ICESat Vertical RMSE"
},
"gmd:result": {
"gmd:DQ_QuantitativeResult": {
"gmd:valueUnit": {
"@xlink:href": "http://www.opengis.net/def/uom/OGC/1.0/metre"
},
"gmd:value": {
"gco:Record": {
"gco:Real": "0.398874"
}
}
}
}
},
{
"gmd:nameOfMeasure": {
"gco:CharacterString": "Difference to GCP LE90"
},
"gmd:result": {
"gmd:DQ_QuantitativeResult": {
"gmd:valueUnit": {
"@xlink:href": "http://www.opengis.net/def/uom/OGC/1.0/metre"
},
"gmd:value": {
"gco:Record": {
"gco:Real": "2.897789"
}
}
}
}
},
{
"gmd:nameOfMeasure": {
"gco:CharacterString": "Difference to GCP Vertical Mean"
},
"gmd:result": {
"gmd:DQ_QuantitativeResult": {
"gmd:valueUnit": {
"@xlink:href": "http://www.opengis.net/def/uom/OGC/1.0/metre"
},
"gmd:value": {
"gco:Record": {
"gco:Real": "-0.383740"
}
}
}
}
},
{
"gmd:nameOfMeasure": {
"gco:CharacterString": "Difference to GCP Vertical RMSE"
},
"gmd:result": {
"gmd:DQ_QuantitativeResult": {
"gmd:valueUnit": {
"@xlink:href": "http://www.opengis.net/def/uom/OGC/1.0/metre"
},
"gmd:value": {
"gco:Record": {
"gco:Real": "1.760134"
}
}
}
}
},
{
"gmd:nameOfMeasure": {
"gco:CharacterString": "Absolute horizontal accuracy CE90"
},
"gmd:result": {
"gmd:DQ_QuantitativeResult": {
"gmd:valueUnit": {
"@xlink:href": "http://www.opengis.net/def/uom/OGC/1.0/metre"
},
"gmd:value": {
"gco:Record": {
"gco:Real": "10"
}
}
}
}
},
{
"gmd:nameOfMeasure": {
"gco:CharacterString": "Absolute vertical accuracy LE90"
},
"gmd:result": {
"gmd:DQ_QuantitativeResult": {
"gmd:valueUnit": {
"@xlink:href": "http://www.opengis.net/def/uom/OGC/1.0/metre"
},
"gmd:value": {
"gco:Record": {
"gco:Real": "10"
}
}
}
}
}
]
在这个例子中我需要检索的对象是最后一个对象(包含字符串“Absolute vertical accuracy LE90”),但我不能指望它总是在同一个位置。我试图通过附加来过滤这个结果集
[?(@['gmd:nameOfMeasure']['gco:CharacterString']=="Absolute vertical accuracy LE90")]
到原来的 jsonpath 表达式(产生新的表达式
$..['gmd:DQ_AbsoluteExternalPositionalAccuracy'][?(@['gmd:nameOfMeasure']['gco:CharacterString']=="Absolute vertical accuracy LE90")]
但是过滤器语句对结果没有影响。只是为了好玩,我在 https://jsonpath.herokuapp.com/ 的 java 的 Jayway jsonpath 实现中尝试了相同的表达式,并成功地将结果过滤到一个所需的对象。
谁能告诉我如何使用 jsonpath-plus 正确过滤这个结果集?
【问题讨论】:
标签: json typescript object filter jsonpath