Dom*_* C. 2 arrays format serialization json cakephp
我正在将CakePHP数组的返回值转换为JSON,目前它是这样的:
{
"platformusers" : [
{
"id" : "1",
"name" : "user1"
},
{
"id" : "3",
"name" : "user3"
}
]
}
Run Code Online (Sandbox Code Playgroud)
我希望它是这样的:
[
{
"id" : "1",
"name" : "user1"
},
{
"id" : "3",
"name" : "user3"
}
]
Run Code Online (Sandbox Code Playgroud)
我正在努力 Set :: extract('{n} .Model',$ data) Hash :: extract('{n} .Model',$ data)根本没有运气.
完整代码:
$platformusers = $this->Platformuser->find('all', array(
'fields' => array('Platformuser.id', 'Platformuser.name')
));
$platformusers = Hash::extract('{n}.Platformuser', $platformusers);
$this->set(array(
'platformusers' => $platformusers,
'_serialize' => array('platformusers')
));
Run Code Online (Sandbox Code Playgroud)
ndm*_*ndm 10
设置string为_serialize选项,而不是一个array.An array表示可能有多个视图变量需要序列化,并且需要将它们打包到单独的对象属性中.
$this->set(array(
'platformusers' => $platformusers,
'_serialize' => 'platformusers'
));
Run Code Online (Sandbox Code Playgroud)
这应该会给你想要的结果.
| 归档时间: |
|
| 查看次数: |
1830 次 |
| 最近记录: |