A, of json_decode () to decode JSON data converted to a variable PHP
语法:json_decode ($json [,$assoc = false [, $depth = 512 [, $options = 0 ]]])
Example:
$book = array('a'=>'xiyouji','b'=>'sanguo','c'=>'shuihu','d'=>'hongloumeng'); $json = json_encode($book); $array = json_decode($json,TRUE); $obj = json_decode($json); var_dump($array); var_dump($obj);
Browser print out the results as follows:
array(4) { ["a"]=> string(7) "xiyouji" ["b"]=> string(6) "sanguo" ["c"]=> string(6) "shuihu" ["d"]=> string(11) "hongloumeng" } object(stdClass)#2 (4) { ["a"]=> string(7) "xiyouji" ["b"]=> string(6) "sanguo" ["c"]=> string(6) "shuihu" ["d"]=> string(11) "hongloumeng" }
Two, json_encode () JSON encoding of variables,
语法: json_encode ( $value [, $options = 0 ] )
- Example:
$book = array('a'=>'xiyouji','b'=>'sanguo','c'=>'shuihu','d'=>'hongloumeng'); $json = json_encode($book); echo $json;
Browser print out the results as follows:
{"a":"xiyouji","b":"sanguo","c":"shuihu","d":"hongloumeng"};
Zero: return json (XXX, 201); // status code 201 may be transmitted to the end of the page