JSON在PHP中的应用 不指定

Sep 28 16:06 出处:本站原创 | |
今天看了一个文章是讲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;

JSON大部分用在JS上面.
Tags: , ,
: 365Key网摘 和讯网摘 我摘网摘 天极网摘 新浪网摘 Del.icio.us(美味书签) QQ书签 Google书签
发表评论
表情
emotemotemotemotemotemotemotemotemotemot
emotemotemotemotemotemotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码 游客无需密码
网址   电邮   [注册]