View Full Version : PHP: JSON decode
6epcepk
27 Sep 2007, 2:27 AM
Hi,
I'm trying to decode JSON data returned from JS:
$array = $json->decode($_POST['delData']);
echo $_POST['delData'];
print_r($array);
die();
But result is:
[{\"id\":\"46\"}]Array
(
[0] =>
)
Where is my mistake?
Thanks.
Monkiman
27 Sep 2007, 3:21 AM
strip slashes ?
is the word "Array" meant to be there ? (I'm a newbie too)
I mean should
[{"id\":\"46\"}]Array
Actually be
[{"id\":\"46\"}]
?
6epcepk
27 Sep 2007, 4:45 AM
Ooops, I'm actyally trying to strip slahes with str_replace, but needed with stripslashes($_POST['delData']);.
genius551v
27 Sep 2007, 6:13 AM
Are you sure you have JSON.php???
devnull
27 Sep 2007, 6:20 AM
there would be an "unknown function" error if json_decode was not available (either through json.php, or if php5 is being used).
did using the stripslashes work? if not, show us the json string as well.
evilized
27 Sep 2007, 7:45 AM
Hi...
i can help with the json decode on the serverside...
on my server, i've a script in php... like this:
print_r(json_decode( stripslashes($vars['asesor']) ) );
so, the json data is decode correctly :)
and for json in php 4.x... i've in my config.inc.php:
if(!function_exists('json_encode'))
{
require_once('JSON.php');
$GLOBALS['JSON_OBJECT'] = new Services_JSON();
function json_encode($value)
{
return $GLOBALS['JSON_OBJECT']->encode($value);
}
function json_decode($value)
{
return $GLOBALS['JSON_OBJECT']->decode($value);
}
}
so, if i've php 4.x ... i can make json_encode and json_decode available...
json.php is the original script from http://mike.teczno.com/JSON/JSON.phps
cchiriac
27 Sep 2007, 7:56 AM
Isn't a backslash missing ? [{\"id\":\"46\"}]
You encoded with Ext ?
Powered by vBulletin® Version 4.1.5 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.