如何正确验证json

时间:2017-10-19 08:32:14

标签: arrays json codeception

我有来自api电话的回应:

[{
    "1": {
        "name": "Euro",
        "iso": "EUR",
        "sign": "€"
    },
    "2": {
        "name": "Dollar",
        "iso": "USD",
        "sign": "$"
    },
    "3": {
        "name": "Pound",
        "iso": "GBP",
        "sign": "£"
    },
    "6": {
        "name": "Czech koruna",
        "iso": "CZK",
        "sign": "Kč"
    },
    "7": {
        "name": "Australian Dollar",
        "iso": "AUD",
        "sign": "A$"
    }, ...
]

我使用seeResponseMatchesJsonType()方法来验证这个数组,但第一个字段是从1到100的某个数字,在seeResponseMatchesJsonType方法中我必须完全指定字段,

不适合我的代码

seeResponseMatchesJsonType(["1"=> [
        "name"=> "Euro",
        "iso"=> "string",
        "sign"=> "string"
    ],...
and that code 100 times or what amount ids I will receive))

1 个答案:

答案 0 :(得分:0)

根据您的情况,我认为使用seeResponseContainsJson代替seeResponseMatchedJsonType会更好。 seeResponseContainsJson可用于验证响应中是否存在json的一部分。 http://codeception.com/docs/modules/REST#seeResponseContainsJson

希望它有所帮助。