【问题标题】:Json Decode giving empty result if there is any special character is there如果有任何特殊字符,Json 解码给出空结果
【发布时间】:2015-10-07 02:58:34
【问题描述】:

在使用json_decode 时,如果存在任何特殊字符,如“带黑钻的问号”,则解码返回空值。

我也使用过 UTF-8 编码。

【问题讨论】:

    标签: php json decoder


    【解决方案1】:

    https://en.wikipedia.org/wiki/JSON#Data_portability_issues - 这就是你想要的? :) 尝试将其打印为 UTF 符号。

    【讨论】:

      【解决方案2】:

      您的问题似乎出在json_encode 部分而不是json_decode 部分。

      看看这个: How to keep json_encode() from dropping strings with invalid characters

      他们建议在您使用json_encode 之前使用iconv 字符串以确保删除所有非法字符。

      引用给出的例子:

      $stripped_of_invalid_utf8_chars_string = iconv('UTF-8', 'UTF-8//IGNORE', $orig_string);
      if ($stripped_of_invalid_utf8_chars_string !== $orig_string) {
          // one or more chars were invalid, and so they were stripped out.
          // if you need to know where in the string the first stripped character was, 
          // then see https://stackoverflow.com/questions/7475437/find-first-character-that-is-different-between-two-strings
      }
      $json = json_encode($stripped_of_invalid_utf8_chars_string);
      

      【讨论】:

        猜你喜欢
        • 2015-01-28
        • 1970-01-01
        • 2023-03-14
        • 2014-07-08
        • 1970-01-01
        • 1970-01-01
        • 2020-12-15
        • 1970-01-01
        • 2018-09-26
        相关资源
        最近更新 更多