Php Json_编码重音问题

Php Json_编码重音问题,php,android,json,Php,Android,Json,我正在尝试用json解析一个网站,以查看我的应用程序中的查询结果。。我有个问题。我使用了json\u encode来显示结果,因为有时我会显示null字符串。我使用这部分代码 $json = array(); if(mysql_num_rows($result)){ while($row=mysql_fetch_assoc($result)){ $json['oscar'][]=$row; $json[] = array_map('utf8_encode', $row); } }

我正在尝试用json解析一个网站,以查看我的应用程序中的查询结果。。我有个问题。我使用了
json\u encode
来显示结果,因为有时我会显示
null
字符串。我使用这部分代码

$json = array(); 

if(mysql_num_rows($result)){ 
while($row=mysql_fetch_assoc($result)){ 
$json['oscar'][]=$row; 

$json[] = array_map('utf8_encode', $row); 
} 
} 

mysql_close($con); 
echo json_encode($json); 
有了这个,我可以显示一些东西,但口音是错误的;例如:

Mor\u00ec would be Morì
$json = array(); 

if(mysql_num_rows($result)){ 
    while($row=mysql_fetch_assoc($result)){ 
        $json['oscar'][]=$row; 
        $json[] = array_map('utf8_encode', $row); 
    } 
} 

mysql_close($con); 
echo json_encode($json); 

等等,在这里你可以看到。如何解决此问题?

您是否尝试过PHP encode的额外参数?例如:

Mor\u00ec would be Morì
$json = array(); 

if(mysql_num_rows($result)){ 
    while($row=mysql_fetch_assoc($result)){ 
        $json['oscar'][]=$row; 
        $json[] = array_map('utf8_encode', $row); 
    } 
} 

mysql_close($con); 
echo json_encode($json); 
改为:

$json = array(); 

if(mysql_num_rows($result)){ 
    while($row=mysql_fetch_assoc($result)){ 
        $json['oscar'][]=$row; 
        $json[] = array_map('utf8_encode', $row); 
    } 
} 

mysql_close($con);
echo json_encode($json, JSON_UNESCAPED_UNICODE);
如图所示

编辑:要查看UTF-8中的响应,您可以尝试将此行添加到页面的开头:

<?php header("Content-Type: text/html; charset=utf-8"); ?>


您的数据库是否使用utf8编码存储值?我正在使用wordpress和PhpMyAdmin,所以老实说我不知道。。我怎么查?在这个例子中,fix?EDIT:我在wp-config.php文件中找到了这一行:
define('DB_CHARSET','utf8')您是否尝试注释掉将行的全部内容转换为“UTF-8”的部分?字符的显示方式似乎是编码问题。数据库似乎已经在UTF8中了,所以再次将其翻译似乎不合适…不,“echo json_encode($json);”转换为:“echo json_encode($json,json_UNESCAPED_UNICODE);”我编辑了答案以使其更容易理解。mmh
警告:json_encode()预计参数2会很长。
我更改了php版本。现在我有了5.4,没有错误。。但现在口音都是
Ã
:(这使事情变得更容易…您的浏览器显示默认编码(在您的示例中为“ISO-8859-1”,这是windows的默认编码。)由于这只是json转储,您没有设置任何元标记来选择默认编码,因此您的浏览器将以ISO-8859-1而不是UTF-8显示它。不必担心程序代码是否读取它,它应该可以。只要确保尝试将您的编码更改为UTF-8。如果您告诉我您使用的浏览器,我甚至可以告诉您如何执行此操作。