【问题标题】:How to display special character in json_decode() in php like "Ñ"如何在 php 中的 json_decode() 中显示特殊字符,如“Ñ”
【发布时间】:2019-09-02 20:22:29
【问题描述】:

我想显示数据库中的名称,但名称包含“Ñ”,结果为“Null”

我正在使用此代码

    $result = array();

    $sth = $dbcon->prepare("MY SELECT CODE HERE");
    $sth->execute();
            while($row_count = $sth->fetch(PDO::FETCH_ASSOC)){
        $result[] = $row_count;
            }
    echo json_encode($result);

这里是结果..你可以看到名称中的空值,因为这个字符串有“Ñ”,而表中有Ñ

[{"emp_id":"12561-2013","name":null,"

【问题讨论】:

标签: javascript php pdo


【解决方案1】:

使用带有 JSON_UNESCAPED_UNICODE 标志的 json_encode,即, json_encode($result, JSON_UNESCAPED_UNICODE);

【讨论】:

  • 我正在使用这个 echo json_encode($result,JSON_UNESCAPED_UNICODE);但结果为“null”
  • 你的 mysql 字符集可能不是 UTF-8。你可以在做 json_encode 之前尝试做 utf8_encode 吗?喜欢,echo json_encode(utf_encode($result));
  • @CalabDonss 如上分享,请尝试:echo json_encode(utf_encode($result));
猜你喜欢
  • 2012-10-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-04-03
  • 1970-01-01
  • 2019-10-14
相关资源
最近更新 更多