json_decode
<?php
/*
json_decode
JSONの文字列をデコードします。
*/
$ary1=array(1,2,3);
$ary2=array(array(4,5,6));
$ary3=array("red"=>1, "blue"=>2, "yellow"=>3);
$result1 = json_encode($ary1);
$result2 = json_encode($ary2);
$result3 = json_encode($ary3);
print "ary1:" . $result1 . "<br />";
print "ary2:" . $result2 . "<br />";
print "ary3:" . $result3 . "<br />";
print "----------------------------<br />";
var_dump(json_decode($result1)) . "<br />";
var_dump(json_decode($result2)) . "<br />";
var_dump(json_decode($result3)) . "<br />";
/*
[出力結果]
ary1:[1,2,3]
ary2:[[4,5,6]]
ary3:{"red":1,"blue":2,"yellow":3}
----------------------------
array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) }
array(1) { [0]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } }
object(stdClass)#1 (3) { ["red"]=> int(1) ["blue"]=> int(2) ["yellow"]=> int(3) }
*/
?>
|
|