如何从 Jmeter 中的 JSON 数组中提取第三个元素

How to extract 3rd element from a JSON array in Jmeter

我需要提取下面 JSON 数组的第 3 个时间元素。

[
    {
        "userId": 1,
        "id": 1,
        "title": " How to Shape of Character Design",
        "write": "Jun Bale",
        "date": "20/12/20",
        "time": "10:00AM",
        "body": " Because he takes  nsuscipit accepted result lightly with  nreprehenderit discomfort may be the entire  nnostrum of the things that happens is that they are extremely ",
        "image": "https://source.unsplash.com/rDEOVtE7vOs/1600x900",
        "tag": ["good", "great", "javascript", "wife"]
    },
    {
        "userId": 1,
        "id": 2,
        "write": "Henry Cavil",
        "
date": "21/12/20",
        "time": "08:00AM",
        "title": " How to Write About Your Life? Start Here .",
        "body": " it is the time of  nseq are not criticize consumer happy that the pain or  nfugiat soothing pleasure forward or no discomfort may rejecting some  nWho, not being due, we may be able to open the man who did not, but there is no ",
        "image": "https://source.unsplash.com/WNoLnJo7tS8/1600x900",
        "tag": ["happy", "USA", "no", "wife"]
    },
    {
        "userId": 1,
        "id": 3,
        "write": "Katrina Tayl,
    "date": "24/12/20",
        "time": "06:49PM",
        "title": " How to Survive as a Freelancer in 2020 ",
        "body": " innocent, but the law  nvoluptatis blinded the election or the  nvoluptatis pains or prosecutors who is to pay nmolestiae and is willing to further or to and from the toil of an odious term ",
        "image": "https://source.unsplash.com/vMV6r4VRhJ8/1600x900",
        "tag": ["indian", "babbyes", "java", "hate"]
    }
]

我尝试使用 JSON 提取器提取 -- $..time[2] & $..['time'][2] 但无济于事。我得到一个空数组。当我尝试使用 $..time 时,我得到 3 个值

[
   "10:00AM",
   "08:00AM",
   "06:49PM"
]

但我只想要第三项,即06:49PM。任何帮助都感激不尽。谢谢

如果你想要 JsonPath 中的解决方案,它会是这样的:

[2].time

演示:

更多信息:

JSON 中似乎存在格式问题。 已更正。

[
   {
      "userId":1,
      "id":1,
      "title":" How to Shape of Character Design",
      "write":"Jun Bale",
      "date":"20/12/20",
      "time":"10:00AM",
      "body":" Because he takes  nsuscipit accepted result lightly with  nreprehenderit discomfort may be the entire  nnostrum of the things that happens is that they are extremely ",
      "image":"https://source.unsplash.com/rDEOVtE7vOs/1600x900",
      "tag":[
         "good",
         "great",
         "javascript",
         "wife"
      ]
   },
   {
      "userId":1,
      "id":2,
      "write":"Henry Cavil",
      "date":"21/12/20",
      "time":"08:00AM",
      "title":" How to Write About Your Life? Start Here .",
      "body":" it is the time of  nseq are not criticize consumer happy that the pain or  nfugiat soothing pleasure forward or no discomfort may rejecting some  nWho, not being due, we may be able to open the man who did not, but there is no ",
      "image":"https://source.unsplash.com/WNoLnJo7tS8/1600x900",
      "tag":[
         "happy",
         "USA",
         "no",
         "wife"
      ]
   },
   {
      "userId":1,
      "id":3,
      "write":"Katrina Tayl",
      "date":"24/12/20",
      "time":"06:49PM",
      "title":" How to Survive as a Freelancer in 2020 ",
      "body":" innocent, but the law  nvoluptatis blinded the election or the  nvoluptatis pains or prosecutors who is to pay nmolestiae and is willing to further or to and from the toil of an odious term ",
      "image":"https://source.unsplash.com/vMV6r4VRhJ8/1600x900",
      "tag":[
         "indian",
         "babbyes",
         "java",
         "hate"
      ]
   }
]

可以在JSON Extractor.

中使用匹配号设置提取特定索引

试试这个,

$..[2]["time"] or $..[2].time

例如:如果我有一个简单的数组,

arr=["A","B","C","D"];

我想从 "arr" 打印 "C"。然后它将使用

arr[2];// result: C; starting index = 0

如果我有一个数组

arr2=[{"x":"A","y":"B"},{"x":"C","y":"D"},{"x":"E","y":"F"}];

我想从 "arr2" 打印 "C"。然后就是

arr2[1]// result: {"x":"C","y","D"}

arr2[1]["x"]// result: C