如何从空手道数组格式的 json 响应中获取值
How to fetch value from a json response which is in array format in karate
我正在尝试从我的响应中获取一个 JSONArray 格式的值。我想从第一个数组对象中获取 Id。
{
"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
但这行不通。
请帮忙
您的 JSON 有误,少了一个逗号。以后请多加小心
粘贴下面的内容,看看它是否有效。
* 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'
我正在尝试从我的响应中获取一个 JSONArray 格式的值。我想从第一个数组对象中获取 Id。
{
"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
但这行不通。
请帮忙
您的 JSON 有误,少了一个逗号。以后请多加小心
粘贴下面的内容,看看它是否有效。
* 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'