2016-05-13 158 views
7

給定一個JSON名單如下:你如何在jsonpath中轉義@符號?

{  
"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/,試圖使這項工作。

回答

1

你顯然需要使用十六進制代碼(我認爲這事做的方式表達被解析)

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

哇!做得好!我不知道你可以插入這樣的代碼,它不在半官方文檔中http://goessner.net/articles/JsonPath/index.html#e2 – redwards510