PHP中的Unicode Json编码问题


Unicode Json Encode issue in PHP

在我的数据库中,它有一些unicode字符,当我:时

$result=mysql_query($query) or die(mysql_error());
while ($row = mysql_fetch_assoc($result)) {
$response[] = $row;
}
echo json_encode($response);

结果是

[{
    "id": "151",
    "titlenews": "iPad2 ? iPhone Mini ????????????? ???????????????? Samsung Galaxy Tab",
    "photo": "ipad_1294990020.jpg"
}, {
    "id": "153",
    "titlenews": "???????????????????????? iPhone 5 ??????????????????? Apple",
    "photo": "iphone-5_1294996201.jpg"
}, {
    "id": "154",
    "titlenews": "Android ??????????????????????????????????? ????????????????????????????????????????????????????? 2010",
    "photo": "android_1295234852.jpg"
}]

为什么它有"?",它应该编码到任何特殊字符来表示unicode。

感谢

这就是我使用的方法

function myencode(&$item,$key)
{
    $item=utf8_encode($item);
}
function my_json_encode($arr)
{
    if(is_array($arr))
    {
        array_walk_recursive($arr,myencode);
        return json_encode($arr);
    }
    else
    {
        return json_encode(array());
    }
}

然后解码

function my_json_decode($json)
{
    return json_decode(safeJSON_chars(stripslashes($json)),TRUE);
}

评论中的解决方案(Savartona):

mysql_set_charset("utf8", $con);