【问题标题】:jsonPath - problem with accessing to field by indexjsonPath - 按索引访问字段的问题
【发布时间】:2021-03-24 20:50:50
【问题描述】:

我尝试通过从 shipping_id 获取值来访问值 Carrier。我在https://www.jsonquerytool.com/ 测试查询。如果我手动键入密钥$.shipping_methods["11"]$.shipping_methods.11我会收到正确的结果["Carrier"]。但是我从shipping_id 字段中获取键值有问题。我尝试了这个$.shipping_methods[$.shipping_id] 的许多变体,但没有成功。纯jsonPath可以吗?

{
   "shipping_id":"11",
   "shipping_methods":{
      "10":"Post",
      "11":"Carrier"
   }
}

【问题讨论】:

  • 这能回答你的问题吗?考虑支持/接受。

标签: json web jsonpath json-path-expression


【解决方案1】:

根据您使用的 JSON-Path 实现/环境,这可能会也可能不会。这是因为您要求的功能不属于proposed standard,尽管某些库具有启用此类查询的功能,例如在JSONPath-Plus 中,您可以使用@property@parent(我使用@root 没有成功)-但这些是“扩展”:

$.shipping_methods[?(@property == @parent.shipping_id)]

你可以测试这个online here

您链接的页面在后台使用JSPath,我看不到自述文件中提到的任何必需功能。使用托管 JSON-Path 引擎的通用编程语言进行深入研究会更简单,但不确定这是否是一个选项。

【讨论】:

    猜你喜欢
    • 2019-07-28
    • 1970-01-01
    • 2018-11-26
    • 2011-12-10
    • 2023-03-12
    • 1970-01-01
    • 2015-12-19
    • 2022-01-07
    • 2016-08-25
    相关资源
    最近更新 更多