Jmeter JSONAssertion 失败消息

Jmeter JSONAssertion Failure Message

while performing the JSON Assertion using Jmeter , i get the following error.

Expected to find object with property $['id'] in path $["body"] but found 'net.minidev.json.JSONArray'. This is not a json object according to the JSON Provider.'com.jayway.jsonpath.spi.json.JsonSmartJsonProvider'.

please let me know what is the issue ?

该错误意味着您的 JsonPath 查询与响应数据中的任何内容都不匹配。

例如,如果您JSON喜欢:

{
  "body": [
    {
      "id": 28,
      "Title": "Sweden"
    },
    {
      "id": 56,
      "Title": "USA"
    },
    {
      "id": 89,
      "Title": "England"
    }
  ]
}

然后您将 JSON Assertion 配置为:

它将失败,因为 JSON 路径查询匹配 > 1 个元素:

为了测试即 28 值,您需要修改 JSON 路径查询以指向 body JSON Array [=21= 中的第一个条目]

$.body[0].id

更多信息:How to Use the JSON Plugin in JMeter