php中json_decode()和json_encode()的使用方法

浏览:14047 发布日期:2015/11/27 分类:求助交流
json_decode() $json = '{"a":1,"b":2,"c":3,"d":4,"e":5}'; 
var_dump(json_decode($json)); 
var_dump(json_decode($json, true)); 
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)
}


json_encode() $arr = array ('a'=>1,'b'=>2,'c'=>3,'d'=>4,'e'=>5); 

echo json_encode($arr); 
{"a":1,"b":2,"c":3,"d":4,"e":5}
最佳答案
评论( 相关
后面还有条评论,点击查看>>