本文實(shí)例講述了php json相關(guān)函數(shù)用法。分享給大家供大家參考,具體如下:
函數(shù)列表:
函數(shù)
描述
json_encode
對(duì)變量進(jìn)行json編碼
json_decode
對(duì)json格式的字符串進(jìn)行解碼,轉(zhuǎn)換為php變量
json_last_error
返回最后發(fā)生的錯(cuò)誤
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:這里再為大家推薦幾款比較實(shí)用的json在線工具供大家參考使用:
在線JSON代碼檢驗(yàn)、檢驗(yàn)、美化、格式化工具:
http://tools.gimoo.net/code/json
JSON在線格式化工具:
http://tools.gimoo.net/code/jsonformat
在線XML/JSON互相轉(zhuǎn)換工具:
http://tools.gimoo.net/code/xmljson
json代碼在線格式化/美化/壓縮/編輯/轉(zhuǎn)換工具:
http://tools.gimoo.net/code/jsoncodeformat
C語言風(fēng)格/HTML/CSS/json代碼格式化美化工具:
http://tools.gimoo.net/code/ccode_html_css_json
更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《PHP中json格式數(shù)據(jù)操作技巧匯總》、《PHP數(shù)學(xué)運(yùn)算技巧總結(jié)》、《PHP基本語法入門教程》、《PHP數(shù)組(Array)操作技巧大全》、《php字符串(string)用法總結(jié)》、《php+mysql數(shù)據(jù)庫操作入門教程》及《php常見數(shù)據(jù)庫操作技巧匯總》
希望本文所述對(duì)大家PHP程序設(shè)計(jì)有所幫助。