dsl - 如何从空手道数组格式的json响应中获取值
问题描述
我正在尝试从我的响应中获取一个 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'
推荐阅读
- python - 使用moviepy加速视频而不是音频
- php - PHP RSS 得到奇怪的字符
- debugging - 在 VSCODE 上调试
- simulation - 测量和显示状态下的代理持续时间
- django - 如何在 jinja (django) 中使用 for 循环显示最新的 5 个订单
- ubuntu - Zerotier cli 命令在 ubuntu 中给出错误“缺少端口和 zerotier-one.port”
- devops - 如何使用 AWS CDK Pipelines 构建不同语言的 lambda
- node.js - Jest 检测到以下 1 个可能阻止 Jest 退出的打开句柄,指向 mongoose 的 openUri
- python - 如何在 Python 中正确使用“not()”运算符
- javascript - 如何将数据从 React 应用程序传递到 Alan Studio 并在 Alan Studio 中接收该数据?