max_
max_

Reputation: 24481

Help editing JSON to make an array rather than a 'dictionary'

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":"..."}}}

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.

Thanks in advanced.

Upvotes: 1

Views: 450

Answers (2)

salathe
salathe

Reputation: 51950

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.

Upvotes: 3

tplaner
tplaner

Reputation: 8461

Take a look at PHP's json_decode function, specifically the 2nd parameter if you want an array.

Upvotes: 0

Related Questions