JSON

php中json_decode返回数组或对象

字号+ 作者:H5之家 来源:H5之家 2015-09-26 10:20 我要评论( )

?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]

<?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) 
}


$data='[{"Name":"a1","Number":"123","Contno":"000","QQNo":""},{"Name":"a1","Number":"123","Contno":"000","QQNo":""},{"Name":"a1","Number":"123","Contno":"000","QQNo":""}]'; 
echo json_decode($data);

结果为:

Array ( [0] => stdClass Object ( [Name] => a1 [Number] => 123 [Contno] => 000 [QQNo] => ) [1] => stdClass Object ( [Name] => a1 [Number] => 123 [Contno] => 000 [QQNo] => ) [2] => stdClass Object ( [Name] => a1 [Number] => 123 [Contno] => 000 [QQNo] => ) )

 

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

相关文章
  • php CI 实战教程:[5]用curl获取json并解析

    php CI 实战教程:[5]用curl获取json并解析

    2016-02-26 17:00

  •  JSON入门级学习总结-JSON数据结构

    JSON入门级学习总结-JSON数据结构

    2016-02-25 11:05

  • Android解析Json速度最快的库:json

    Android解析Json速度最快的库:json

    2016-02-13 18:00

  • JavaScript转换与解析JSON方法实例详解第1/2页

    JavaScript转换与解析JSON方法实例详解第1/2页

    2016-02-10 21:25

网友点评
s