$user = $this->User->find( 'all' );
$this->set( 'users', $user );
我的控制器中有这段代码。
在我看来,我有这个。
echo json_encode( compact( 'users' ) );
它像这样输出json
{
"users": [{
"User": {
"user_id": "2",
"email": "email@test.com",
"name": "Blah"
}]
}
}
无论如何要格式化它以删除包装在“用户”中的整个数组,并删除每个作为“用户”成员的对象。
这使得在前端使用起来更加困难。我希望它看起来像这样。
[{
"user_id": "2",
"email": "email@test.com",
"name": "Blah"
}]
谢谢你的帮助。