json_encode和json_decode例子,json.php是utf-8编码才支持中文,如果是用gb2312中文可能什么东西都不输出
<?php
$arr = array(
'name' => '大黄',
'say' => '人之初',
'contact' => array(
'email' => 'hjwtp2005at163.com',
'website' => 'http://www.emtit.com',
)
);
$json_string = json_encode($arr);
echo $json_string.'<hr>';
$obj = json_decode($json_string);
echo $obj;
?>
javascript
<script language="javascript">
var arr ={"name":"/u5927/u9ec4","say":"/u4eba/u4e4b/u521d","contact":{"email":"hjwtp2005at163.com","website":"http:www.emtit.com"}};
var obj=arr.contact;
alert('website:'+obj.website)
</script>