Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:42243 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 76956 invoked from network); 14 Dec 2008 06:10:42 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 14 Dec 2008 06:10:42 -0000 Authentication-Results: pb1.pair.com smtp.mail=xuefer@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=xuefer@gmail.com; sender-id=pass; domainkeys=bad Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.142.185 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: xuefer@gmail.com X-Host-Fingerprint: 209.85.142.185 ti-out-0910.google.com Received: from [209.85.142.185] ([209.85.142.185:30021] helo=ti-out-0910.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 85/72-47862-163A4494 for ; Sun, 14 Dec 2008 01:10:42 -0500 Received: by ti-out-0910.google.com with SMTP id u3so1351389tia.17 for ; Sat, 13 Dec 2008 22:10:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:sender :to:subject:cc:in-reply-to:mime-version:content-type :content-transfer-encoding:content-disposition:references :x-google-sender-auth; bh=TVqee+Z/UgZTBFSLaoXT4CooMUP+OY8aaVMilEo2JPo=; b=whjVMxaWZHijktNnaS6ES5paplwC/REvPGVTOXj4EGiAMsz5/Nlgu5K3A9OQTlr4kC VZGkMuWtiqsY8tdyN09aE5wjx9jU1/GIWgLaJYoASd/CkyVbH0r1N5EOdtrV1fLNhNIi 75h8lyuO7APDtdU8AHFU3Nm6CtXneXDe3RXGs= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:sender:to:subject:cc:in-reply-to:mime-version :content-type:content-transfer-encoding:content-disposition :references:x-google-sender-auth; b=CVV0vUn5HApLHVVFdwh0kIwypdWZBaWRzYcaWQ67Oj3lYna+I0AKfe/ew5bnS6oRJn MrAoV4z3vCB/5WWPdEnJxzMSYJRvU6CeV2AGaJgX+SUFXmv2RC1KVgn99khQHfvf4sFm MEAthB0JvkeyqVTF3KhG+t9AAtU2bA7LoWEiI= Received: by 10.110.53.19 with SMTP id b19mr8004575tia.39.1229235038160; Sat, 13 Dec 2008 22:10:38 -0800 (PST) Received: by 10.110.53.9 with HTTP; Sat, 13 Dec 2008 22:10:38 -0800 (PST) Message-ID: <28139bc0812132210p1ed94f4ds40e31ff499cf2e7@mail.gmail.com> Date: Sun, 14 Dec 2008 14:10:38 +0800 Sender: xuefer@gmail.com To: "Rasmus Lerdorf" Cc: "Stan Vassilev | FM" , "PHP Developers Mailing List" In-Reply-To: <49448D66.2030501@lerdorf.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <2D85B33E-889B-4214-9BB8-A12EFFFC641E@macvicar.net> <1229150500.30719.201.camel@localhost> <4BA26FE8A9634178B4CEBEFA818810D2@VEGA> <15E310EAB433466EAF996B252CBED2BB@pc> <49448D66.2030501@lerdorf.com> X-Google-Sender-Auth: 625af312bb656c19 Subject: Re: [PHP-DEV] Removing basic types from our JSON parser From: moo.tinys@gmail.com (moo . tinys) > > I'm not sure if that is the right way of looking at it though. I think > the only question is how to represent the scalar types, not whether they > should be allowed. As far as I am concerned it is obvious that they be > allowed and the JSON spec is quite explicit that JSON can be used to > represent scalar types: > > JSON can represent four primitive types (strings, numbers, > booleans, and null) and two structured types (objects and arrays). > > The only question is how to serialize these into a JSON-text string. > Again, from the RFC: > > A JSON text is a sequence of tokens. The set of tokens includes six > structural characters, strings, numbers, and three literal names. > > A JSON text is a serialized object or array. > > This last statement is the issue. When serializing a basic type into a > JSON text string, the RFC says we need to wrap it inside an array or > object. So, if we are going to add an option to json_encode(), that's > what the option should do. Specify whether, and perhaps how, to wrap > basic types, not whether to allow or disallow them. > > I'll talk to Douglas on Monday if he is in the office and get his opinion. > > -Rasmus cool. let's see how :D. Crockford explain it :D but before he can react on this thread, i guess Rasmus is right understanding the RFC. json force your encoder to output the following in encoded form 1. array: "multiple of unnamed" values 2. object: "multiple of named" values so it's right to "wrap it" in object or array (u can say "remove basic types") json_encode(array(1)); => [1] json_encode(array(1, 2, 3, "1")); => [1,2,3,"1"] json_encode(array('value1' => 1)); => {"value1":1} json_encode(array('a'=>1, 'b'=>2, 'c'=>3, 'd'=>"1")); => {"a":1, "b":2,"c":3,"d":"1"} i'd prefer 2 new functions: js_encode (or js_export?) js_decode which support basic types instead of having an extra optional parameter