JSON JSON 的路径

JSONPath for the JSON

我有以下JSON

 {
  "RestResponse": {
    "messages": [
        "Total [36] records found."
    ],
    "result": [
        {
            "id": 56,
            "country": "IND",
            "name": "Andhra Pradesh",
            "abbr": "AP",
            "area": "49506799SKM",
            "largest_city": "Hyderabad Amaravati",
            "capital": "Hyderabad Amaravati"
        }
    ]
   }
 }

要访问名称,我尝试将 JSON路径指定为

 $RestResponse.result[*].name

也为

 $RestResponse.result[:1].name

两者似乎都不起作用。

您需要将其更改为$.RestResponse.result[*].name。点符号从根元素 $ 开始很重要,就像在 jsonpath 查询的每个其他部分一样。

JSONPath expressions can use the dot–notation or the bracket–notation for input pathes. Learn JsonPath

  • 括号符号

    $['RestResponse']['result'][0]['name']

  • 点符号

    $.RestResponse.result[0].name

您可以试试 JsonPath 表达式测试器 here