json_decode
json_decode — JSON 文字列をデコードする
説明
mixed json_decode ( string json [, bool assoc] )JSON エンコードされた文字列を受け取り、それを PHP の変数に変換します。
パラメータ
- json
-
デコード対象となる json 文字列。
- assoc
-
TRUE の場合は、返されるオブジェクトが連想配列形式になります。
返り値
オブジェクトを返します。あるいは、オプションのパラメータ assoc が TRUE の場合には、 連想配列を返します。例
例 1003. json_decode() の例
<?php
$json = '{"a":1,"b":2,"c":3,"d":4,"e":5}';
var_dump(json_decode($json));
var_dump(json_decode($json, true));
?>
上の例の出力は以下となります。object(stdClass)#1 (5) { ["a"] => int(1) ["b"] => int(2) ["c"] => int(3) ["d"] => int(4) ["e"] => int(5) } array(5) { ["a"] => int(1) ["b"] => int(2) ["c"] => int(3) ["d"] => int(4) ["e"] => int(5) }
参考
json_encode() |
- json_decodeのページへのリンク