我正在使用cakephp 2.x并使用以下内容返回一些json数据;我想从结果中删除模型名称User,因此只返回键和值。
$this->set('_serialize', 'json');
我的结果以下列格式返回;
[
{
"User": {
"fullname": "John Smith"
}
},
{
"User": {
"fullname": "Jiles Smith"
}
}
}
]
我尝试了以下内容;
$json = json_encode(Set::extract('/User/.', $json));
但它的回复就像;
"[{\"fullname\":\"Ashley Smith\"},{\"fullname\":\"Leigh Smith\"},{\"fullname\":\"Charlie Chocolate\"}]"
答案 0 :(得分:2)
@ndm发布了上面的解决方案。我会将他的回答标记为正确,但我不确定如何做到。
解决方案是替换
$json = json_encode(Set::extract('/User/.', $json);
带
$json = Set::extract('/User/.', $json);