dsgnze6572 2014-06-04 20:51
浏览 42

json_encode无法解析utf8表中的字符串[重复]

This question already has an answer here:

i've seen some posts about this topic.

I have a string that contains the letter é. I need to json_encode this string, but the function will return null. In other posts it is said that the reason behind this, is the fact that the string is not a utf-8 encoded string. So, it needs to be a utf-8 encoded string to work.

The problem is, the string comes directly from the database, and the table it originates from is encoded as utf-8. So how is the string i'm trying to parse to a json object not utf-8? Am i missing something?

</div>
  • 写回答

1条回答 默认 最新

  • duanpen9294 2014-06-04 21:03
    关注

    Have you tried encoding it into UTF-8 and then saving it into the database using something like iconv(), or maybe before parsing it to a json ?

    IE:

    $utfchar = iconv('Windows-1252', 'UTF-8','é');
    

    EDIT:

    You Also need to set the browser's charset to utf8, this for example works:

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <?php
        $test = iconv('Windows-1252', 'UTF-8','é');
        echo $test;
    ?>
    
    <script type="text/javascript">
        var jstest = '<?php echo $test; ?>';
        console.log(jstest);
    </script>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示