【问题标题】:How do you escape the @ symbol in jsonpath?如何在 jsonpath 中转义 @ 符号?
【发布时间】:2016-09-10 06:45:12
【问题描述】:

给定一个像这样的 json 列表:

    {    
 "listRel:customFieldList": {
            "platformCore:customField": [
              {
                "@internalId": "801",
                "scriptId": "custentity_admin_contact_cweb",
                "@xsi:type": "platformCore:BooleanCustomFieldRef",
                "platformCore:value": "false"
              },
              {
                "@internalId": "712",
                "@scriptId": "custentity_bar_number",
                "@xsi:type": "platformCore:StringCustomFieldRef",
                "platformCore:value": "166493"
              },
              {
                "@internalId": "798",
                "@scriptId": "custentity_contact_type",
                "@xsi:type": "platformCore:SelectCustomFieldRef",
                "platformCore:value": {
                  "@internalId": "1",
                  "@typeId": "148",
                  "platformCore:name": "Attorney"
                }
              }
              ]
 }
}

如何选择“custentity_bar_number”中的值? 166493?

这将使您到达那里,但前提是您删除 JSON 中 @scriptId 前面的 @ 符号。

$..['platformCore:customField'][?(@['scriptId'] == 'custentity_bar_number')]

所以我需要一种方法来转义 json 中的 @ 符号,并使类似这样的工作:

$..['platformCore:customField'][?(@['@scriptId'] == 'custentity_bar_number')]

我正在使用http://jsonpath.com/ 来尝试完成这项工作。

【问题讨论】:

    标签: json jsonpath


    【解决方案1】:

    您显然需要使用十六进制代码(我认为这与解析表达式的方式有关)

    $..['platformCore:customField'][?(@['\x40scriptId'] == 'custentity_bar_number')]
    

    【讨论】:

    • 哇!做得好!我不知道你可以插入这样的代码,它不在半官方文档中goessner.net/articles/JsonPath/index.html#e2
    • 我尝试使用包含@的键直接选择一个值。这对我不起作用(其他也没做,括号,引号,转义......)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-11-12
    • 2013-09-15
    • 2013-11-22
    • 2019-01-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多