php解析Json,json_encode()函數(shù)用法
接受一個(gè) JSON 格式的字符串并且把它轉(zhuǎn)換為 PHP 變量
定義和用法
json_decode(json_str,true) 把JSON 格式的字符串轉(zhuǎn)換為 PHP數(shù)組或?qū)ο?/span>
語(yǔ)法:
json_decode(value,option)
value:必填。待解碼的json字符串 。該函數(shù)只能接受 UTF-8 編碼的數(shù)據(jù)
option:可選 默認(rèn) false 轉(zhuǎn)為對(duì)象。true 轉(zhuǎn)為數(shù)組。
例子:
<?php $json = '{"a":1,"b":2,"c":3,"d":4,"e":5}'; var_dump(json_decode($json)); var_dump(json_decode($json, true)); ?>以上例程會(huì)輸出:
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) }
原文鏈接:php解析Json,json_decode()函數(shù)用法