php json_decode 函數


json_decode 函數

url地址:http://php.net/manual/en/function.json-decode.php

json_decode 
(PHP 5 >= 5.2.0, PECL json >= 1.2.0) 

json_decode — 對 JSON 格式的字符串進行編碼 

說明 
mixed json_decode ( string $json [, bool $assoc ] ) 
接受一個 JSON 格式的字符串並且把它轉換為 PHP 變量 

參數 

json 
待解碼的 json string 格式的字符串。 

assoc 
當該參數為 TRUE 時,將返回 array 而非 object 。

Example #1 json_decode() examples

<?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)
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM