PHP使用JSON中文乱码解决实例
来源:网络 责任编辑:栏目编辑 发表时间:2013-07-01 04:39 点击:次
json.php
<?php
$json = array (
0 => array (
id => 13,
name => 乒乓球,
),
1 => array (
id => 17,
name => 篮球,
)
);
print_r($json);
$code=json_encode($json);
echo preg_replace("#\u([0-9a-f] )#ie", "iconv(UCS-2, UTF-8, pack(H4, \1))", $code);
?>
json.html
<script>
$.getJSON("json.php",
function(data) {
for (var i = 0; i < data.length; i ) {
alert(data[i].name);
}
});
</script>
<?php
$json = array (
0 => array (
id => 13,
name => 乒乓球,
),
1 => array (
id => 17,
name => 篮球,
)
);
print_r($json);
$code=json_encode($json);
echo preg_replace("#\u([0-9a-f] )#ie", "iconv(UCS-2, UTF-8, pack(H4, \1))", $code);
?>
json.html
<script>
$.getJSON("json.php",
function(data) {
for (var i = 0; i < data.length; i ) {
alert(data[i].name);
}
});
</script>
相关新闻>>
- 发表评论
-
- 最新评论 更多>>