【发布时间】:2015-10-13 06:45:30
【问题描述】:
在 cakephp 中,我有一些编码为 json 的数据(例如:$projects= json_encode($projects);),但我的 php 控制器返回错误的数据模式!我的 json 返回数据在“[]”中,我无法以角度 ng-repeat 访问这种形式的数据以供查看!怎么了?
这是我的 cakephp 控制器的一些部分:
public function admin_getprojects()
{
$projects = $this->Project->find('all',array(
'contain'=>array('UsersProjects'=>array('User'),
'Task')
));
$this->set('projects', $projects);
$projects= json_encode($projects);
echo $projects;
exit();
}
返回数据: view of json data in json parser... this shouldn't have "[" and "]" at begin and end
【问题讨论】:
-
实际上它取决于你的数组结构,如果你在数组的第一个元素中有一个键,那么它将返回 "{" 否则将返回 [
-
固定代码格式。
标签: php json angularjs cakephp