karate - 空手道如何解析字符串化的 json 响应
问题描述
我得到了这样的回应。
"{\"statusCode\":204,\"output\":\"{\\n \\\"Id\\\" : \\\"884d39b8-4afc-4ee3-807a-9d6dbde8c390\\\",\\n \\\"temp\\\" : \\\"33\\\",\\n \\\"lastUpdateAuthor\\\" : null\\n}\"}"
我怎样才能解析这个响应并做类似的事情
* def expectedOutput =
"""
{
"Id": "884d39b8-4afc-4ee3-807a-9d6dbde8c390",
"temp": "33",
"lastUpdateAuthor": null
}
Scenario: Testing a PUT endpoint with request body
Given path 'v0'
And request input
When method put
Then match status 200
And match JSON.parse(JSON.parse(response).output) == expectedOutput
空手道跳过了最后一行代码。
有输入吗?
解决方案
想通了。
* def expectedOutput =
"""
{
"Id": "884d39b8-4afc-4ee3-807a-9d6dbde8c390",
"temp": "33",
"lastUpdateAuthor": null
}
"""
Scenario: Testing a PUT endpoint with request body
Given path 'v0'
And request input
When method put
Then match status 200
And json convertJSON = $
And json convertJSON = convertJSON.output
And match convertJSON.latitude == expectedOutput
有效。
推荐阅读
- godot - 如何在 GDNS 文件中添加注释?
- javascript - 将具有相同文本的 SPAN 删除到 DOM 元素数组中
- google-cloud-platform - 在 GCP 中编写对象生命周期规则时了解 IsLive 和存储类
- elasticsearch - Elasticsearch POST /delete_by_query 不起作用
- reactjs - 如何从 json 访问图表中的颜色?
- excel - 动态用户 ID 连接 excel 连接到 Azure 分析服务
- python - 想在python中重命名2个具有不同扩展名的文件
- python - BeautifulSoup 在开发工具中找不到元素
- c++ - 使用 Gmock 调用成员函数
- javascript - 在Vue js中对表格进行排序