如何从空手道数组格式的json响应中获取值 [英] How to fetch value from a json response which is in array format in karate

查看:61
本文介绍了如何从空手道数组格式的json响应中获取值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从响应中获取一个JSONArray格式的值.我想从第一个数组对象中获取ID.

I am trying to fetch a value from my response which comes in a JSONArray format. I want to fetch the Id from the first array object.

{
  "count": 1,
  "next": "",
  "previous": "",
  "list": [
    {
      "id": "f78bde61-056a-4358-bbac-50bf524c965c",
      "name": "Auto_Approval",
      "description": "Lambda Functions Demo",
      "context": "hjk",
      "version": "v1",
      "provider": "hk",
      "status": "PUBLISHED",
      "thumbnailUri": null
    },
    {
      "id": "f78bde61-056a-4358-bbac-50bf524c965c",
      "name": "Auto_Approval",
      "description": "Lambda Functions Demo",
      "context": "knkl",
      "version": "v1",
      "provider": "uygi",
      "status": "PUBLISHED",
      "thumbnailUri": null
    }
  ],
  "pagination": {
    "total": 1,
    "offset": 0,
    "limit": 25
  }
}

我想获取id的值.

我尝试了 response.list [0] .id ,但这不起作用.

I tried response.list[0].id but this is not working.

请帮助

推荐答案

您的JSON错误,缺少逗号.以后请多加小心.

You have a mistake in your JSON, a comma is missing. Kindly be more careful in future.

粘贴以下内容,然后查看其效果.

Paste the below and see it work.

* def response = 
"""
{
   "count":1,
   "next":"",
   "previous":"",
   "list":[
      {
         "id":"f78bde61-056a-4358-bbac-50bf524c965c",
         "name":"Auto_Approval",
         "description":"Lambda Functions Demo",
         "context":"hjk",
         "version":"v1",
         "provider":"hk",
         "status":"PUBLISHED",
         "thumbnailUri":null
      },
      {
         "id":"f78bde61-056a-4358-bbac-50bf524c965c",
         "name":"Auto_Approval",
         "description":"Lambda Functions Demo",
         "context":"knkl",
         "version":"v1",
         "provider":"uygi",
         "status":"PUBLISHED",
         "thumbnailUri":null
      }
   ],
   "pagination":{
      "total":1,
      "offset":0,
      "limit":25
   }
}
"""
* def id = response.list[0].id
* match id == 'f78bde61-056a-4358-bbac-50bf524c965c'

这篇关于如何从空手道数组格式的json响应中获取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆