Re: Formatting output with json_encode
| From: | Evert Lammerts | Date: | Mon, 14 Jul 2008 09:30:38 +0000 |
| Subject: | Re: Formatting output with json_encode | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-45144@lists.php.net to get a copy of this message | ||
Check out http://www.json.org/ for JSON structures.
In javascript an Array object is a special implementation of the
Object object (like all objects other than Object) - an Array object
can only have numerical indices, an Object object can have textual
indices too. If you json_encode a php array with textual indices it
translates to {...} - a javascript Object object. If you json_encode a
php array with numerical indices it translates to [...] - a javascript
Array object.
It seems to me that what you're using is mysql_fetch_array
(http://nl3.php.net/manual/en/function.mysql-fetch-array.php) with
either no result_type parameter set, or result_type set to MYSQL_BOTH.
If you want a javascript Array object, use either
mysql_fetch_array($result, MYSQL_NUM) or mysql_fetch_row($result). If
you want a javascript Object object, use either
mysql_fetch_array($result, MYSQL_ASSOC) or mysql_fecth_assoc($result).
Evert
On Mon, Jul 14, 2008 at 8:21 AM, Ron Piggott <ron.php@actsministries.org> wrote:
> I am using json_encode to output the results of a mySQL query which is
> part of a jquery & ajax.
>
> $result = json_encode($array);
> echo $result;
>
> The output on my screen is:
>
> {0:"John 14:27","verse_reference":"John 14:27"}
>
> How do I format json_encode output? I would like
>
> John 14:27
>
> to be what is displayed.
>
> Ron
>
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>