java - 如何解析和获取一些,验证来自使用 Java 的放心 api 中的响应的值
问题描述
我开始放心地学习,并设法做出响应并从服务器获取数据。但我无法解析和验证值。对于我的研究,我正在尝试获取所有数据并解析和验证。如果你解释我怎么做做,我会很高兴。这是我的代码:
@Test
public void getRequest() {
String key ="key";
String token= "token";
String id ="idvalue";
Response response = given().spec(new RequestSpecBuilder().setBaseUri("https://api.trello.com/1").setContentType(ContentType.JSON)
.build())
.log().all()
.when()
.queryParams("key", key,
"token",
token)
.pathParam("id", id)
.get("/cards/{id}");
response.then().statusCode(200)
//.body("name", hasItems("value"));//I want to check all of variables actually.this line not working.
}
邮递员的回复也在这里:
{
"id": "607ff8e3dd2e81327e55c05d",
"checkItemStates": [],
"closed": false,
"dateLastActivity": "2021-04-21T10:05:23.805Z",
"desc": "",
"descData": null,
"dueReminder": null,
"idBoard": "607eee0d9f781d012c9407c9",
"idList": "607f1a4e92b92d8fa44e07b8",
"idMembersVoted": [],
"idShort": 14,
"idAttachmentCover": null,
"idLabels": [],
"manualCoverAttachment": false,
"name": "güncellemekarti2",
"pos": 114688,
"shortLink": "5NTDEAXD",
"isTemplate": false,
"cardRole": null,
"dueComplete": false,
"due": null,
"email": null,
"labels": [],
"shortUrl": "https://trello.com/c/5NTDEAXD",
"start": null,
"url": "https://trello.com/c/5NTDEAXD/14-g%C3%BCncellemekarti2",
"idMembers": [],
"badges": {
"attachmentsByType": {
"trello": {
"board": 0,
"card": 0
}
},
"location": false,
"votes": 0,
"viewingMemberVoted": false,
"subscribed": false,
"fogbugz": "",
"checkItems": 0,
"checkItemsChecked": 0,
"checkItemsEarliestDue": null,
"comments": 0,
"attachments": 0,
"description": false,
"due": null,
"dueComplete": false,
"start": null
},
"subscribed": false,
"idChecklists": [],
"cover": {
"idAttachment": null,
"color": null,
"idUploadedBackground": null,
"size": "normal",
"brightness": "dark",
"idPlugin": null
}
}
解决方案
hasItems() 更适合数组 - 在你的情况下,试试这个:
.body("name", is("güncellemekarti2"));
推荐阅读
- file - 将自己文件夹中的松散文件批量复制到新的重命名文件夹
- r - `list2env()` 可能存在的错误
- python - 有没有办法区分按下的按钮Flask
- docker - docker container rabbitmqctl shutdown 卡住“等待 PID xxx 终止”
- sql - left 与 right outer JOIN 的意义何在
- xcode - Xcode 应用程序升级到 12.3 后将无法构建
- html - 添加内容时表格单元格缩小 (Firefox; contenteditable="true")
- sql - PostgreSQL Upsert 用于几乎相似的值
- sql-server - 使用脚本将过程副本保存在同一数据库中
- excel - 使用变量过滤 Excel 中的图表