帮助编辑JSON以创建数组,而不是“字典" [英] Help editing JSON to make an array rather than a 'dictionary'
本文介绍了帮助编辑JSON以创建数组,而不是“字典"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我目前有一个从mysql查询中使用json_encode的json,如下所示:
I currently have json using json_encode from a mysql query which looks like this:
{"post_2":{"caption":"...","id":"...","accountID":"..","date":"07\/07\/2011 1:45:12 AM","title":"...","authorInfo":{"Email Address":"..."}}}, {"post_2":{"caption":"...","id":"...","accountID":"..","date":"07\/07\/2011 1:45:12 AM","title":"...","authorInfo":{"Email Address":"..."}}}
我如何让json是帖子数组("post_2","post_1")而不是字典? JSON将在iPhone上使用SBJSON解码,并且必须将JSON制成后端的数组.
How can I have the json being an array of posts ('post_2', 'post_1') rather than it being a dictionary? The JSON will be decoded on an iPhone using SBJSON and the JSON will have to be made into an array in the backend.
非常感谢.
推荐答案
为json_encode()
提供非关联数组.最简单的方法通常是简单地在(关联)数组上调用array_values()
并对结果进行编码.
Provide a non-associative array to json_encode()
. The easiest way is usually to simply call array_values()
on the (associative) array, and encode the result.
这篇关于帮助编辑JSON以创建数组,而不是“字典"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文