"value1", "item2"=>"value2");
var $boolean = true;
var $integer = 5;
var $float = 1.12;
var $innerobject;
function object1()
{
$this->innerobject = new object2();
}
}
class object2
{
var $firstattr = 'firstvalue';
var $secondattr = 'secondvalue';
}
//---- variables ---------------------------------------------------------------
$JSON = new JSON();
$object1 = new object1();
$JSON2 = new Services_JSON();
$submitted = false;
//---- logic -------------------------------------------------------------------
$origjsonstring = $JSON->stringify($object1);
$newjsonstring = $JSON2->encode($object1);
$origjson = $_REQUEST["origjson"];
if (!empty($origjson))
{
$origjsonprintr = $JSON->parse(stripslashes($origjson));
$submitted = true;
}
else
{
$origjsonprintr = "Not submitted";
}
$newjson = $_REQUEST["newjson"];
if (!empty($newjson))
{
$newjsonprintr = $JSON2->decode(stripslashes($newjson));
}
else
{
$newjsonprintr = "Not submitted";
}
//---- content -----------------------------------------------------------------
?>
JSON parser test
Original JSON PHP/Javascript
Original PHP object (print_r)
|
Result of PHP Stringify
|
Did it Convert to a Javascript Object origjsobj ?
|
Result of Javascript Stringify
|
Result of Conversion Back to PHP object (print_r)
|
|
New JSON PHP/Javascript
Original PHP object (print_r)
|
Result of PHP Stringify
|
Did it Convert to a Javascript Object newjsobj ?
|
Result of Javascript Stringify
|
Result of Conversion Back to PHP object (print_r)
|
|