Just saw a video on why this is by Douglass Crockford....
Technically, you can use unquoted labels ala {var1:"value1"}, but JavaScript will have errors when you try to use reserved words like "for" and "switch". Rather than write the JSON standard for labels using: Attribute names can be unquoted as long as they are not these words: for, which, ... Crockford decided to just require that labels in object literals must always be quoted. - jake 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? > > > > > > > > > > > > > > -- > > Ⓙⓐⓚⓔ - יעקב ʝǡǩȩ ᎫᎪᏦᎬ > -- Ⓙⓐⓚⓔ - יעקב ʝǡǩȩ ᎫᎪᏦᎬ