从php返回非utf8

时间:2014-04-30 15:52:52

标签: php json

从数据库读取值并将它们作为json传递时,我遇到了问题。

我从DB中读取了很好的值并且读得很好但是当我尝试将其传递给json格式时,它会给出null。

这是我的代码:

$stmt = $db->prepare("SELECT id, title, lat, lon FROM POI_Table WHERE attribution=:attribution");
    $stmt->execute(array(':attribution'=>$attribution));

$x = -1;

while($res = $stmt->fetch(PDO::FETCH_ASSOC)) {
    $x++;
    $data[$x] =  array(
    "id" => $res['id'],
    "title" =>  $res['title'] , 
    "lat" => $res['lat'] , 
    "lon" => $res['lon']
      );
}
if($x > -1){
    echo json_encode($data);
}

当我有一个带口音的单词ex:“música”时,它返回null。

我不知道为什么因为它正在读取其他数据库中的值。所以我认为它与口音格式有关。在添加到数组之前,我如何转换或编码为正确的格式?

0 个答案:

没有答案