Blogger Information
Blog 263
fans 3
comment 2
visits 113271
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
json格式数据的使用
福哥的博客
Original
1009 people have browsed it
<?php
/* ***json编码***
[1,2,5,7,8,"hello",[6,7,8],{"h":"hello"}]
{"h":"hello","w":"world",[1,2,3]}//h为key,hello为value,即k=>v对,K与v用:隔开,多个k=>v对之间用逗号隔开
*/
$arr=array(1,2,5,8,'hello','xuexi',array('h'=>'Hello','name'=>'xuexi'));
//print_r($arr);
//echo json_encode($arr);//json_encode()把数据转换为Joson格式
//输出:[1,2,5,8,"hello","xuexi",{"h":"Hello","name":"xuexi"}]
?>
<?php
$obj =array('h'=>'hello','w'=>'world',array(3,2,1));
//echo json_encode($obj);
//输出:{"h":"hello","w":"world","0":[3,2,1]}
?>
<?php
//***json解码***
$jsonstr = '{"h":"hello","w":"world","0":[3,2,1]}';
$obj = json_decode($jsonstr);
//print_r($obj);
//输出:stdClass Object ( [h] => hello [w] => world [0] => Array ( [0] => 3 [1] => 2 [2] => 1 ) ) 
echo $obj->h;
//输出:hello
?>


Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post