RE: [PHP-DEV] json_encode()
| From: | Jared Williams | Date: | Mon, 15 Dec 2008 18:23:11 +0000 |
| Subject: | RE: [PHP-DEV] json_encode() | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-42268@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: mike [mailto:mike503@gmail.com]
> Sent: 15 December 2008 18:10
> To: Rasmus Lerdorf
> Cc: PHP Developers Mailing List
> Subject: Re: [PHP-DEV] json_encode()
>
> On Mon, Dec 15, 2008 at 9:50 AM, Rasmus Lerdorf
> <rasmus@lerdorf.com> wrote:
>
> > 1. Document the fact that if you want to strictly conform
> to the JSON
> > spec and be sure your json_encode output will work in various JSON
> > parsers, you have to pass it a PHP array or object.
>
> Instead of json_encode(34) the suggestion would be
> json_encode(array(34)) ? Seems kind of like a lame thing to require.
> IMHO the language should "do the right thing" as far as the
> consumer (javascript/JSON parser) is concerned. However,
> Douglas is infinitely more educated than I am here. This is
> just my $0.02 as a PHP user.
Don't think that's what he said... More like...
assert(is_object($foo) || is_array($foo)); // ensure strictly
conforming
$json = json_encode($foo);
Jared