【问题标题】:json decode for special characters [duplicate]特殊字符的json解码[重复]
【发布时间】:2014-02-05 05:11:42
【问题描述】:

我有一个字符串test éàå。当我执行 json_encode 时,特殊字符被转换为 test u00e9u00e0u00e5

现在在执行 json_decode 时,我没有取回原始字符,而是保留为 test u00e9u00e0u00e5

谁能帮我找回特殊字符。

【问题讨论】:

  • 提示u00e9é的UTF8编码

标签: php json


【解决方案1】:

json_encodejson_decode 仅适用于 UTF-8 编码的字符串。

为确保它在您的网页中正确显示,请使用 utf-8 字符集。

<!DOCTYPE html>
<html lang="en">
<head>    
<meta charset="utf-8">    
</head>
<body>
<?php
    $string = 'test éàå';
    $json = json_encode($string);
    echo json_decode($json);
?>
</body>
</html>

【讨论】:

  • 谢谢...这很完美。但是如果我在数据库中插入一个数据数组并试图取回它,例如 json_encode($_POST);我尝试这样做 json_decode($result) 它仍然给我编码的特殊字符。
  • 确保 html 表单是 utf-8 格式,插入和检索数据应该没有问题。
  • 抱歉愚蠢的问题。我怎样才能确保这一点。而且我正在使用 index.php 然后执行插入到 dbase
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-03-22
  • 2014-08-02
  • 1970-01-01
  • 2018-06-28
  • 2019-08-28
相关资源
最近更新 更多