PHP json_encode()UTF-8特殊字符失败

时间:2013-07-30 18:14:32

标签: php json encoding utf-8

我正在使用html_entity_decode($ string)来解码html特殊字符,例如& auml =ä。然后我使用json_encode()创建一个用于Android应用程序的json字符串。我的问题是我得到了\ u00e4而不是'ä'的输出。我知道json_encode()仅适用于UTF-8编码的字符串,但是当我对我的值运行mb_detect_encding($ myString)时,它返回“UTF-8”。在值上运行ut8_encode()没有帮助。这是我的代码:

$newsList = array();
while($row = $news->fetch_object()){
  $tmpNews = new News();
  $tmpNews->imgId = $row->image_id;
  $tmpNews->author = html_entity_decode($row->author);
  $tmpNews->subject = $row->subject;
  $tmpNews->msg = $row->msg;
  $tmpNews->newsmsg = $row->newsmsg;
  $tmpNews->date = $row->wdate;
  array_push($newsList, $tmpNews);
  $tmpNews = null;
}

$json = array();
foreach($newsList as $news){
  array_push($json, $news->getJson());
}
var_dump($json);
echo json_encode($json);

当我执行var_dump($ json)时,我的特殊字符显示为正常。

0 个答案:

没有答案