douxia3505 2016-08-13 19:22
浏览 160

带有特殊字符的JSON

Please I am having some problem with my json file and I am hoping someone can help me. I have searched but can not fully understand the solution i found.

I have checked here json with special characters like é with no luck and some other places too.

Here is my json array script

<?php

$response = array();

require_once __DIR__ . '/db_connect.inc.php';

$result = mysql_query("SELECT id, name, artist_id, year, length, ndisc, keywords, hits, image, review, user_id, tags, genre_id, added, album_file FROM albums ORDER BY id DESC") or die(mysql_error());

if (mysql_num_rows($result) > 0) {

    $response["albums"] = array();

    while ($row = mysql_fetch_array($result)) {

        $album = array();
        $album["id"] = $row["id"];
        $album["name"] = $row["name"];
        $album["artist_id"] = $row["artist_id"];
        $album["year"] = $row["year"];
        $album["length"] = $row["length"];
        $album["ndisc"] = $row["ndisc"];
        $album["keywords"] = $row["keywords"];
        $album["hits"] = $row["hits"];
        $album["image"] = $row["image"];
        $album["review"] = $row["review"];
        $album["user_id"] = $row["user_id"];
        $album["tags"] = $row["tags"];
        $album["genre_id"] = $row["genre_id"];
        $album["added"] = $row["added"];
        $album["album_file"] = $row["album_file"];

        array_push($response["albums"], $album);
    }

    $response["success"] = 1;

    echo json_encode($response);
    } else {
    $response["success"] = 0;
    $response["message"] = "No album found";

    echo json_encode($response);
}

?>

This works fine when there is no special character text in the array. So the problem I am having with this is that it doesn't return anything when special character text such as é, ö, Ø etc is in any of the array field.

So what I want to know is please how can i rewrite this my json script to retrieve those value?

Thank you very much in advance.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
    • ¥15 求daily translation(DT)偏差订正方法的代码
    • ¥15 js调用html页面需要隐藏某个按钮
    • ¥15 ads仿真结果在圆图上是怎么读数的
    • ¥20 Cotex M3的调试和程序执行方式是什么样的?
    • ¥20 java项目连接sqlserver时报ssl相关错误
    • ¥15 一道python难题3
    • ¥15 牛顿斯科特系数表表示
    • ¥15 arduino 步进电机
    • ¥20 程序进入HardFault_Handler