php json相關(guān)函數(shù)用法示例
本文實例講述了php json相關(guān)函數(shù)用法。分享給大家供大家參考,具體如下:
函數(shù)列表:
函數(shù) | 描述 |
---|---|
json_encode | 對變量進(jìn)行json編碼 |
json_decode | 對json格式的字符串進(jìn)行解碼,轉(zhuǎn)換為php變量 |
json_last_error | 返回最后發(fā)生的錯誤 |
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互相轉(zhuǎn)換工具:
http://tools.jb51.net/code/xmljson
json代碼在線格式化/美化/壓縮/編輯/轉(zhuǎn)換工具:
http://tools.jb51.net/code/jsoncodeformat
C語言風(fēng)格/HTML/CSS/json代碼格式化美化工具:
http://tools.jb51.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ù)庫操作技巧匯總》
希望本文所述對大家PHP程序設(shè)計有所幫助。
- php返回json數(shù)據(jù)函數(shù)實例
- PHP使用json_encode函數(shù)時不轉(zhuǎn)義中文的解決方法
- php json_encode()函數(shù)返回json數(shù)據(jù)實例代碼
- PHP json_decode函數(shù)詳細(xì)解析
- Javascript生成json的函數(shù)代碼(可以用php的json_decode解碼)
- PHP json_encode() 函數(shù)詳解及中文亂碼問題
- 老版本PHP轉(zhuǎn)義Json里的特殊字符的函數(shù)
- php格式化json函數(shù)示例代碼
- php5.2以下版本無json_decode函數(shù)的解決方法
- PHP自定義函數(shù)格式化json數(shù)據(jù)示例
- java解析php函數(shù)json_encode unicode 編碼問題
- 關(guān)于php中的json_encode()和json_decode()函數(shù)的一些說明
相關(guān)文章
PHP變量作用域(全局變量&局部變量)&global&static關(guān)鍵字用法實例分析
這篇文章主要介紹了PHP變量作用域(全局變量&局部變量)&global&static關(guān)鍵字用法,結(jié)合實例形式分析了PHP全局變量與局部變量的作用域,以及global、static關(guān)鍵字功能與使用技巧,需要的朋友可以參考下2020-01-01PHP Undefined index報錯的修復(fù)方法
用$_GET["xx"]這種形式取得數(shù)據(jù)時,如果之前不加判斷,$_GET["xx"]不存在時會出現(xiàn)這樣的警告:PHP Notice: undefined index xxx。2011-07-07在php中實現(xiàn)限流ip次數(shù)以及允許部分ip訪問的代碼示例
這篇文章給大家介紹了如何在php中實現(xiàn)限流ip次數(shù)以及允許部分ip訪問,文中通過代碼示例給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)具有一定的參考價值,需要的朋友可以參考下2023-12-12