码迷,mamicode.com
首页 > Web开发 > 详细

json_encode和json_decode

时间:2016-06-04 11:54:37      阅读:153      评论:0      收藏:0      [点我收藏+]

标签:

<?php 
$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_decode($data,true)输出的一个关联数组,由此可知json_decode($data)输出的是对象,而json_decode("$arr",true)是把它强制生成PHP关联数组. 

json_encode和json_decode

标签:

原文地址:http://www.cnblogs.com/hyh123/p/5558297.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!