解決Android上面中文json亂碼

23 5 月 尚無留言

設定範例:

<?php
session_start();
ob_start();
include_once("../admin/include/config.php");
include_once("../admin/include/function.php");
//include_once(dirname(__FILE__).'/include/sessioncontrol.php');
mysql_query ( "set names utf8" ); //設定SQL字符為UTF8
$text="select * from tv_channel" ;
$res=mysql_query($text);
$text_new='';
$rows= array();
while($txt=mysql_fetch_array($res))
{
//$text_new.= $txt['c_id'].$txt['c_name'].$txt['c_url'].'#';
	$rows[]=$txt;
}
//echo substr($text_new,0,-1);
//print json_encode($rows);
//使用Foreach遍历数组 同时使用urlencode处理 含有中文的字段
foreach ( $rows as $key => $value){
  $newData[$key] = $value;
  $newData[$key]['channel_name'] = urlencode( $value['channel_name']);
}
print urldecode(json_encode($newData));
?>

相關訊息