//编码
<?php
$arr = array(
'name' => '林平之',
'nick' => 'haran',
'contact' => array(
'email' => 'url at qq dot com',
'website' => 'http://www.url.com',
)
);
$json_string = json_encode($arr);
echo $json_string;
?>
//解码
<?php
$arr = array(
'name' => '林平之',
'nick' => 'haran',
'contact' => array(
'email' => 'url at qq dot com',
'website' => 'http://www.url.com',
)
);
$json_string = json_encode($arr);
$obj = json_decode($json_string);
print_r($obj);
echo $obj->name;
echo $obj->contact->email;
//加TURE直接输出数组
print_r(json_decode($json_string,TRUE));
$arr = json_decode($json_string,TRUE);
echo $arr['name'];
?>
<?php
$arr = array(
'name' => '林平之',
'nick' => 'haran',
'contact' => array(
'email' => 'url at qq dot com',
'website' => 'http://www.url.com',
)
);
$json_string = json_encode($arr);
echo $json_string;
?>
//解码
<?php
$arr = array(
'name' => '林平之',
'nick' => 'haran',
'contact' => array(
'email' => 'url at qq dot com',
'website' => 'http://www.url.com',
)
);
$json_string = json_encode($arr);
$obj = json_decode($json_string);
print_r($obj);
echo $obj->name;
echo $obj->contact->email;
//加TURE直接输出数组
print_r(json_decode($json_string,TRUE));
$arr = json_decode($json_string,TRUE);
echo $arr['name'];
?>