相关疑难解决方法(0)

json_encode返回NULL?

由于某种原因,项目"description"返回NULL以下代码:

<?php
include('db.php');

$result = mysql_query('SELECT * FROM `staff` ORDER BY `id` DESC LIMIT 2') or die(mysql_error());
$rows = array();
while($row = mysql_fetch_assoc($result)){
    $rows[] = $row;
}

echo json_encode($rows);
?>
Run Code Online (Sandbox Code Playgroud)

这是我的数据库的架构:

CREATE TABLE `staff` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` longtext COLLATE utf8_unicode_ci,
  `description` longtext COLLATE utf8_unicode_ci,
  `icon` longtext COLLATE utf8_unicode_ci,
  `date` longtext COLLATE utf8_unicode_ci,
  `company` longtext COLLATE utf8_unicode_ci,
  `companyurl` longtext COLLATE utf8_unicode_ci,
  `appurl` longtext COLLATE utf8_unicode_ci,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=5 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
Run Code Online (Sandbox Code Playgroud)

以下是页面上的回显: …

php null json

117
推荐指数
6
解决办法
11万
查看次数

问题json_encode utf-8

我的json_encode函数有特殊字符的问题.

例如,我试试这个:

$string="Svr?ek";

echo "ENCODING=".mb_detect_encoding($string); //ENCODING=UTF-8

echo "JSON=".json_encode($string); //JSON="Svr\u010dek"
Run Code Online (Sandbox Code Playgroud)

如何正确显示字符串,JSON ="Svrček"?

非常感谢你.

php json utf-8 character-encoding

17
推荐指数
3
解决办法
7万
查看次数

标签 统计

json ×2

php ×2

character-encoding ×1

null ×1

utf-8 ×1