2016-02-02 14:32
浏览 1.7k


I'm using the following code to get JSON from a page and parse it to my HTML page. The JSON is not being displayed in UTF-8 and therefore has weird characters. How can I remove the weird characters?

$.get("test.php", function (data) {
    var JSON = jQuery.parseJSON(data);
    $.each(, function (index, value) {
        // My code

图片转代码服务由CSDN问答提供 功能建议

我正在使用以下代码从页面获取JSON并将其解析为我的HTML页面。 JSON没有以UTF-8显示,因此具有奇怪的字符。 如何删除奇怪的字符?

 var JSON = jQuery.parseJSON(data); \  n $ .each(,function(index,value){
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongzaizai2015 2016-02-02 14:43

    Please make sure that every single step of your process is in UTF-8:

    • The database connection
    • The database tables
    • Your PHP file
    • The content-type headers that you output

      header('Content-Type: application/json; charset=utf-8');

      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">

    Refer to: PHP json_encode json_decode UTF-8

    EDIT: If you already have weird characters like \u00a3 in your JSON feed instead of the £ symbol, your problem has already been answered:

    点赞 评论

相关推荐 更多相似问题