本文 14064 pv
1
JSON大部分用在JS上面.
JSON在PHP中的应用
© kekehu / 技术资源 / 2008.09.28 / 16:06 / 14064PV
今天看了一个文章是讲json的记录一下$name=iconv("GBK", "UTF-8", '这一技客');//编码转成utf-8,json_encode不支特GBK
//定义数组
$arr = array(
'name' => $name,
'ping' => 'geekso',
'contact' => array(
'website' => 'http://www.geekso.com',
)
);
//json_encode编码
$json_string = json_encode($arr);
//json_decode编码
$obj=json_decode($json_string);
//@header("Content-Type:text/html; charset=utf-8");
//把对像转成数组
//$arr=(array) $obj;
//print_r($arr);
//echo $obj->name;
@header("Content-Type:text/html; charset=utf-8");
echo $display=<<<html
<script type="text/javascript">
var arr = {$json_string};
alert(arr.name)
</script>
html;
//定义数组
$arr = array(
'name' => $name,
'ping' => 'geekso',
'contact' => array(
'website' => 'http://www.geekso.com',
)
);
//json_encode编码
$json_string = json_encode($arr);
//json_decode编码
$obj=json_decode($json_string);
//@header("Content-Type:text/html; charset=utf-8");
//把对像转成数组
//$arr=(array) $obj;
//print_r($arr);
//echo $obj->name;
@header("Content-Type:text/html; charset=utf-8");
echo $display=<<<html
<script type="text/javascript">
var arr = {$json_string};
alert(arr.name)
</script>
html;
JSON大部分用在JS上面.
2012.12.06 10:03