【发布时间】:2013-12-13 21:22:53
【问题描述】:
我阅读了很多关于这个主题的帖子,我尝试了很多解决方案,但我无法将这个多数组转换为 JSON 字符串。这是我print_r($result)时看到的:
Array ( [profiles] =>
Array ( [0] =>
Array ( [ID] => 00000000-0000-0000-0000-000000000001
[UserName] => Administrator GU
[Age] => 37
[CityStateCode] => Montréal
[OnlineSince] => En ligne depuis 6 heures 39 minutes
[IsPaying] => true
[LabelOnlineStatus] => En ligne
)
[1] =>
Array ( [ID] => ab3dd04e-5621-11e3-b448-103f0c805f5a
[UserName] => Guillaume Le Genie
[Age] => 68
[CityStateCode] => Montréal
[OnlineSince] => En ligne depuis 1 jour 9 heures
[IsPaying] => true
[LabelOnlineStatus] => Hors-Ligne
)
[2] =>
Array ( [ID] => 00000000-0000-0000-0000-000000000050
[UserName] => Baby-dragoon
[Age] => 25
[CityStateCode] => Québec
[OnlineSince] => En ligne depuis 5 jours 6 heures
[IsPaying] => true
[LabelOnlineStatus] => Hors-Ligne
)
)
)
我试试这个(带和不带 true 参数):
$result = json_encode($result, true);
$error = json_last_error_msg();
echo "[ERROR : $error]-----[$result]-----";
我收到:
[ERROR : Malformed UTF-8 characters, possibly incorrectly encoded]-----[]-----
当我尝试这个时:
$result = json_encode(htmlspecialchars(utf8_encode($result)));
我收到:
警告:utf8_encode() 期望参数 1 是字符串,数组在 /Applications/XAMPP/xamppfiles/htdocs/cdn/php/functionsv1.php 中的 2839行>
[错误:没有错误]-----[""]-----
当我尝试这个时:
$result = json_encode(htmlspecialchars($result));
我收到:
警告:htmlspecialchars() 期望参数 1 为字符串,数组在 /Applications/XAMPP/xamppfiles/htdocs/cdn/php/functionsv1.php 中的第 2839 行
[错误:无错误]-----[null]-----
我真的迷路了!
注意你看语言是法语,所以我们有一个带有 éèàô 等口音的字符......
MySQL数据库提供的数据,数据库设置为:
mysql_query("SET NAMES 'utf8'");
mysql_query('SET CHARACTER SET utf8');
【问题讨论】:
-
你说是$result2,但你正在尝试使用$result
-
抱歉 2 是打字错误!我编辑我的帖子!