json_decode—對JSON格式的字元串進行解碼。
json_decode函數說明
(PHP5>=5.2.0,PECLjson>=1.2.0)
json_decode—對JSON格式的字元串進行解碼
函數定義編輯
mixedjson_decode(string$json[,bool$assoc])
接受一個JSON格式的字元串並且把它轉換為PHP變數
參數
json
待解碼的jsonstring格式的字元串。
assoc
當該參數為TRUE時,將返回array而非object。
返回值
返回一個對象,如果assoc參數選項為true,將會返回一個關聯數組。
json_decode實例說明
用json_decode()函數將JSON格式的字元串編碼。
<?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)
}[1]
總之,json_decode給大家簡單的介紹了一些,希望大家多看看。