This assumes, of course, that you:

A) Are using PHP 5.2
B) Have the json extension installed from PECL[1]

If neither of those apply to you, then there a bunch of pure PHP packages
listed in the PHP section near the bottom of http://www.json.org.

[1] pecl.php.net/package/JSON

On 6/18/07, Michael Geary <[EMAIL PROTECTED]> wrote:

 json_encode should also produce valid JSON, which this isn't:

   {ok:true,state:'OUT-DECOMMISSIONED'}

That is a valid JavaScript object literal, so it will work in most cases
when the "JSON" code is being loaded by JavaScript, but if you ever need to
feed JSON into a strict JSON parser it won't work.

Valid JSON for this would be:

   {"ok":true,"state":"OUT-DECOMMISSIONED"}

IOW, all labels must be quoted, and all quotes are double quotes, not
single quotes. See http://json.org/ for the full syntax.

-Mike

 ------------------------------
*From:* ????

Jake,
   json_encode is very cool, and it looks like it would take care of
everyone's problems...
THANKS!

On 6/18/07, Jake McGraw < [EMAIL PROTECTED]> wrote:
>
> I think Jake nailed it, when using php and json, why not use
> json_encode? Observe:
>
> echo json_encode(array("ok"=>true,"state"=>"OUT-DECOMMISSIONED"));
>
> php-json is native in PHP 5.2 and above, and available as a plugin here:
>
> http://aurore.net/projects/php-json/
>
> and will always* produce valid json from arrays.
>
> - jake
>
> * - As much as I've used it, I haven't come across a single problem.
>
> On 6/18/07, Ⓙⓐⓚⓔ <[EMAIL PROTECTED]> wrote:
> > do you have variables named OUT and DECOMMISSIONED?
> >
> > or did you mean 'OUT-DECOMMISSIONED'
> >
> > as in
> >
> > <?
> > echo "{ok:true,state:'OUT-DECOMMISSIONED'}";
> > > ?>
> >
> >
> >
> > On 6/18/07, Brad Perkins < [EMAIL PROTECTED]> wrote:
> > >
> > > I'm trying to use getJSON to return some JSON from a PHP page. I can
> > > see that the request is returning the expected response with
> Firebug,
> > > but the getJSON callback isn't firing?
> > >
> > > My PHP is simply
> > >
> > > <?
> > > echo "{ok:true,state:OUT-DECOMMISSIONED}";
> > > ?>
> > >
> > > Do a need to set a special content type before returning the JSON?
> > >
> > >
> >
> >
> >
> > --
> > Ⓙⓐⓚⓔ - יעקב   ʝǡǩȩ   ᎫᎪᏦᎬ
>



--
Ⓙⓐⓚⓔ - יעקב   ʝǡǩȩ   ᎫᎪᏦᎬ




--
Aaron Heimlich
Web Developer
[EMAIL PROTECTED]
http://aheimlich.freepgs.com

Reply via email to