首页 > 解决方案 > 如何从响应中验证类型?

问题描述

我必须检查 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”是字符串等。如何放心?

标签: rest-assured

解决方案


最好的方法是

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);

推荐阅读