|
|

<?php
$arr = array(
'name' => '陈毅鑫',
'nick' => '深空',
'contact' => array(
'email' => 'shenkong at qq dot com',
'website' => 'http://www.chenyixin.com',
)
);
$json_string = json_encode($arr);
echo $json_string;
?>
<?php
$arr = array(
'name' => '陈毅鑫',
'nick' => '深空',
'contact' => array(
'email' => 'shenkong at qq dot com',
'website' => 'http://www.chenyixin.com',
)
);
$json_string = json_encode($arr);
$obj = json_decode($json_string);
print_r($obj);
?>
<?php
$arr = array(
'name' => '陈毅鑫',
'nick' => '深空',
'contact' => array(
'email' => 'shenkong at qq dot com',
'website' => 'http://www.chenyixin.com',
)
);
$json_string = json_encode($arr);
echo $json_string;
?>
<?php
$arr = array(
'name' => '陈毅鑫',
'nick' => '深空',
'contact' => array(
'email' => 'shenkong at qq dot com',
'website' => 'http://www.chenyixin.com',
)
);
$json_string = json_encode($arr);
$obj = json_decode($json_string);
print_r($obj);
?>
。需要指出的是,在非UTF-8编码下,中文字符将不可被encode,结果会出来空值,所以,如果你使用gb2312编写PHP代码,那么就需要将包含中文的内容使用iconv或者mb转为UTF-8再进行json_encode.
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/digmouse/archive/2009/03/08/3968556.aspx |
|