note 88889 added to function.json-decode

From: Date: Thu, 12 Feb 2009 09:52:45 +0000
Subject: note 88889 added to function.json-decode
Groups: php.notes 
Request: Send a blank email to php-notes+get-150561@lists.php.net to get a copy of this message
There are error in the preg_replace line:(remove the space) $json = preg_replace('/(^|,)([\\s\\t]*)([^:]*) (([\\s\\t]*)):(([\\s\\t]*))/s', '$1"$3"$4:', trim($json)); change to $json = preg_replace('/(^|,)([\\s\\t]*)([^:]*)(([\\s\\t]*)):(([\\s\\t]*))/s', '$1"$3"$4:', trim($json)); And if try json like this : { test:{t:1,j:0,q:1,w:0,c:1,l:20,s:8}, second:{t:1,j:0,q:1,w:0,c:1,l:50,s:50}, another:{t:2,j:0,q:1,w:0} } it is not work......... json string change to : { "test":{t:1,"j":0,"q":1,"w":0,"c":1,"l":20,"s":8}, "second":{t:1,"j":0,"q":1,"w":0,"c":1,"l":50,"s":50}, "another":{t:2,"j":0,"q":1,"w":0} } .....{t:1,........"second":{t:1,...........,"another":{t:2,....... must be .....{"t":1,......"second":{"t":1,.........,"another":{"t":2,....... if regex expression change to $json = preg_replace('/([{,])([\n\t\s]*)([a-zA-Z0-9\s]+)[\n\s\t]*:/', '$1"$3":', trim($json)); or $json = preg_replace('/([{,])([\n\t\s]*)([^:]+)[\n\s\t]*:/', '$1"$3":', trim($json)); and not need to remove curly brackets this function is work if change this way function is change to : function json_code ($json) { $json = preg_replace('/([{,])([\n\t\s]*)([a-zA-Z0-9\s]+)[\n\s\t]*:/', '$1"$3":', trim($json)); return json_decode($json, true); } ---- Server IP: 69.147.83.197 Probable Submitter: 88.233.27.94 ---- Manual Page -- http://www.php.net/manual/en/function.json-decode.php Edit -- https://master.php.net/note/edit/88889 Del: integrated -- https://master.php.net/note/delete/88889/integrated Del: useless -- https://master.php.net/note/delete/88889/useless Del: bad code -- https://master.php.net/note/delete/88889/bad+code Del: spam -- https://master.php.net/note/delete/88889/spam Del: non-english -- https://master.php.net/note/delete/88889/non-english Del: in docs -- https://master.php.net/note/delete/88889/in+docs Del: other reasons-- https://master.php.net/note/delete/88889 Reject -- https://master.php.net/note/reject/88889 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#150561) next »