$a = array(‘1‘=>‘11‘,‘2‘=>‘22‘,‘3‘=>‘99‘);//无序的下标,则json_encode后变数组形json, 是花括号 { } json_decode后变对象
$b = json_encode($a);
var_dump($b);
var_dump(json_decode($b));
string(28) "{ "1":"11","2":"22","3":"99" }" 对象型json
object(stdClass)#6 (3) { ["1"]=> string(2) "11" ["2"]=> string(2) "22" ["3"]=> string(2) "99" }
$a = array(‘0‘=>‘11‘,‘1‘=>‘22‘,‘2‘=>‘99‘); //下标从0开始,递增,则json_encode后变数组形json, 是中括号的[ ] json_decode后变数组
$b = json_encode($a);
var_dump($b);
var_dump(json_decode($b));
string(16) "["11","22","99"]"
array(3) { [0]=> string(2) "11" [1]=> string(2) "22" [2]=> string(2) "99" }
时间: 2025-01-01 10:27:02