小问题,如何纠正检查JSON,通过代码接收GET收到。
来了..
{
"brands":[
{
"letter":"b",
"list":[
{
"text_ident":"brand1",
"title":"brand1",
"shortDescription":"brand1brand1"
},
{
"text_ident":"brand2",
"title":"brand2",
"shortDescription":"brand2brand2"
},
{
"text_ident":"brand3",
"title":"brand3",
"shortDescription":"brand3brand3"
}
]
},
{
"letter":"v",
"list":[
{
"text_ident":"vrand3",
"title":"vrand3",
"shortDescription":"vrand3vrand3"
}
]
}
]
}
这是BrandsMenuCept.php测试 我用......开始吧。
$fix = new app\tests\api\v1\fixtures\BrandsFixture();
$fix->load();
$I = new ApiTester($scenario);
$I->wantTo('test GET v1/brands/menu');
$I->sendGet('http://example.com/v1/brands/menu');
$I->seeResponseCodeIs('200');
$I->seeResponseIsJson();
$I->seeResponseJsonMatchesJsonPath('$.brands');
...
我应该写什么,如何检查多个数组?
答案 0 :(得分:0)
你可以这样做: 首先使用类似
的真实参数对json_decode进行响应$responsearr=json_decode($json, true);
然后你可以像这样检查数组的计数:
if(count($responsearr)>0){
//logic follows here...
}else{
//invalid json message comes here
}