rest-assured - 如何从响应中验证类型?
问题描述
我必须检查 json 响应是否包含所需的类型。我是什么意思:
{
"success": {
"anonym_id": 11156,
"has_empty_profile": false,
"token": "4690e404-cfec-4918-b555-2f0d84675eee",
"twins": [],
"uid": 7380
}
}
所以我必须检查“anonym_id”是int(不是像这里11156这样的特定数字,而只是int),“has_empty_profile”是布尔值,“token”是字符串等。如何放心?
解决方案
最好的方法是
JsonPath js1 = new JsonPath(new File(
"Your Json I stored in a file"));
assertTrue(js1.get("success.findAll {anonym_id -> anonym_id=11156}.has_empty_profile") instanceof Boolean);
assertTrue(js1.get("success.findAll {anonym_id -> anonym_id=11156}.token") instanceof String);
推荐阅读
- python - Python - MySQL 中的 TIMEDIFF() 函数没有在查询中获取小时部分
- javascript - 如何在单击时切换按钮颜色并在再次单击时将颜色更改回以前的颜色
- javascript - 如何通过数组属性过滤对象数组
- xml - 在 Spring-Boot Intro 之后,“无法找到合适的主类,请添加 'mainClass' 属性”
- mongodb - 无法从 Golang 中的 MongoDB 结果中解码 ObjectId SubValue
- sql - 如何用wordpress连接sql数据库
- javascript - 如何将特定功能分配给一个 JS 文件中的不同 HTML 页面?
- c++ - 用户输入逻辑运算符符号或数字,输入字符或字符串无效
- vlc - 如何更改通过 VLC 本地共享流式传输到 Apple TV 的已播放电影中的音轨?
- python - 无法使用 bs4 在 div 中收集 href