如何从json响应中删除密钥? [英] How to remove key from json response?
本文介绍了如何从json响应中删除密钥?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个集合$tree
,正在使用Response::json()
将其转换为json.该键将自动设置为第一个对象的id
.有没有一种方法可以删除它,或使用以下方法进行重组:
I've got a collection $tree
that is being converted to json with Response::json()
. The key is being automatically set to the id
of the first object. Is there a way to remove this, or restructure with:
'data': [
{ first object },
{ second object}
]
它当前正在响应:
{"1":{"id":"1","parent_id":null,"lft":"1","rgt":"8","depth":"0"...
当我想要的时候是:
{'data':[{"id":"1","parent_id":null,"lft":"1","rgt":"8","depth":"0"...
推荐答案
尝试使用:
Response::json(array( 'data' => array_values($yourDataArray) ) )
;
这篇关于如何从json响应中删除密钥?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文