本文實例講述了php json相關函數用法。分享給大家供大家參考,具體如下:
函數列表:
函數 | 描述 |
---|---|
json_encode | 對變量進行json編碼 |
json_decode | 對json格式的字符串進行解碼,轉換為php變量 |
json_last_error | 返回最后發生的錯誤 |
For example 1: json_encode
$arr=array("A"=>"a","B"=>"b","C"=>"c","D"=>"d"); echo json_encode($arr);
output:
{"A":"a","B":"b","C":"c","D":"d"}
For example 2: json_decode
$arr='{"A":"a","B":"b","C":"c","D":"d"}'; var_dump(json_decode($arr)); var_dump(json_decode($arr,true));
output:
object(stdClass)[1] public 'A' => string 'a' (length=1) public 'B' => string 'b' (length=1) public 'C' => string 'c' (length=1) public 'D' => string 'd' (length=1) array (size=4) 'A' => string 'a' (length=1) 'B' => string 'b' (length=1) 'C' => string 'c' (length=1) 'D' => string 'd' (length=1)
PS:這里再為大家推薦幾款比較實用的json在線工具供大家參考使用:
在線JSON代碼檢驗、檢驗、美化、格式化工具:
http://tools.jb51.net/code/json
JSON在線格式化工具:
http://tools.jb51.net/code/jsonformat
在線XML/JSON互相轉換工具:
http://tools.jb51.net/code/xmljson
json代碼在線格式化/美化/壓縮/編輯/轉換工具:
http://tools.jb51.net/code/jsoncodeformat
C語言風格/HTML/CSS/json代碼格式化美化工具:
http://tools.jb51.net/code/ccode_html_css_json
【網站聲明】本站除付費源碼經過測試外,其他素材未做測試,不保證完整性,網站上部分源碼僅限學習交流,請勿用于商業用途。如損害你的權益請聯系客服QQ:2655101040 給予處理,謝謝支持。