站长论坛

标题: php json数据抓取 [打印本页]

作者: superadmin    时间: 2009-7-25 23:14
标题: php json数据抓取
<?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




欢迎光临 站长论坛 (http://www.tzlink.com/bbs/) Powered by Discuz! X3.2