得到????标记为来自php的响应,而不是获取泰米尔语文本字符串。

时间:2017-05-04 14:48:53

标签: php android web-services android-studio

我在桌子上有泰米尔语文本,而我使用PHP检索数据我得到了???作为回应。

以下是我的PHP代码。

    <?php 
header( 'Content-Type: text/html; charset=utf-8' );
include('connection.php');

$query = "SELECT * FROM DevotionalCollection";
$fetch=mysqli_query($con, $query ) or die(mysqli_error($con));

if (mysqli_num_rows($fetch) > 0) {
    $response["data"] = array();
    while ($row = mysqli_fetch_array($fetch)) {

        $data = array();
        $data["playlistname"] = $row["playlistname"];
        $data["playlistid"] = $row["playlistid"];
        $data["channelname"] = $row["channelname"];
        $data["imageURL"] = $row["imageURL"];

        //$response["data"] = array();
        array_push($response["data"], $data);

    }
    header('Content-type: text/json');
    $response["success"] = TRUE;
    // echoing JSON response
    echo json_encode($response);
}else {
    // no products found
    $response["success"] = FALSE;
    $response["message"] = "No data found";

    // echo no users JSON
    echo json_encode($response);
}

?>

我得到回应

    {
  "data": [
    {
      "playlistname": "?????",
      "playlistid": "PLfLdj4WW-kHU4f4CGm2F9vG--ggvcy7PD",
      "channelname": "Lalitha Lalli",
      "imageURL": ""
    },
    {
      "playlistname": "Colour kolam. ???? ????????. Colour muggulu. Rangoli designs",
      "playlistid": "PLBYk4p11EVuoay-_RpW1x4f6N2eaE6rOO",
      "channelname": "TD Kolam",
      "imageURL": ""
    },
    {
      "playlistname": "Easy Rangoli. ????????. Muggulu",
      "playlistid": "PLBYk4p11EVuqkpL3gwAK2uDZfzyoLM5vW",
      "channelname": "TD Kolam",
      "imageURL": ""
    },
    {
      "playlistname": "?????",
      "playlistid": "PL7PWXzhNZZ0QRVUHZkouHO-Z6ONhPlejT",
      "channelname": "Sumathy G",
      "imageURL": ""
    },
    {
      "playlistname": "?????",
      "playlistid": "PLajt0f8unQ6XqkA_y41ypby_0_9lTf6s_",
      "channelname": "Selvamani Jayabal",
      "imageURL": ""
    },
    {
      "playlistname": "???????????? ???????",
      "playlistid": "PL_wM35e-Czjnzsa-97-IFOmEhOWIrJn1C",
      "channelname": "A to Z Nandhini",
      "imageURL": ""
    },
    {
      "playlistname": "Chikku kolangal",
      "playlistid": "PLSll0nWLklOE9i26_A8-wMHYM91ls-j_p",
      "channelname": "Dr.B.Selvamuthu Krishnan",
      "imageURL": ""
    },
    {
      "playlistname": "Pink",
      "playlistid": "PL-u817lYZC9GXncSo4pnnOp6EG0L-cuCk",
      "channelname": "jagan sekar",
      "imageURL": ""
    },
    {
      "playlistname": "Sk",
      "playlistid": "PLa7cnEZgdw5SH7ZMZENjF650Vv8CDY93L",
      "channelname": "Suresh Kalai",
      "imageURL": ""
    },
    {
      "playlistname": "Popular Videos - Kolam & Puja",
      "playlistid": "PL_ZkVSTePDMvkw9c6CLMCqxc7GlqD3EDU",
      "channelname": "Kolam - Topic",
      "imageURL": ""
    },
    {
      "playlistname": "Rangoli Design-Kolam Design",
      "playlistid": "PLFpOXrFtpgWhqGOQad3PdRZ-QUrBkOZ8l",
      "channelname": "Nagu's Handwork",
      "imageURL": ""
    },
    {
      "playlistname": "Kolam",
      "playlistid": "PLhSkx3hNgucQiXYpgrIZzcBSrBVr7Rr0D",
      "channelname": "Jamuna Rani",
      "imageURL": ""
    },
    {
      "playlistname": "Kambi kolam",
      "playlistid": "PLybpr3Tk6SmVFQ7QolQ2Pt45KbTu9IQKp",
      "channelname": "Balasubramanian Krishnamurthy",
      "imageURL": ""
    },
    {
      "playlistname": "Rangoli borders. kolam border. muggulu border",
      "playlistid": "PLBYk4p11EVupclfP6C4RbjHBu-9ylr1q9",
      "channelname": "TD Kolam",
      "imageURL": ""
    },
    {
      "playlistname": "CHIKKU KOLAM",
      "playlistid": "PLfvmbqiPYkkpuLW8psUOVz-kLCRu2EZcE",
      "channelname": "thilagalakshmi sridharan",
      "imageURL": ""
    },
    {
      "playlistname": "Popular Rangoli & Kolam videos",
      "playlistid": "PLxE-NIHKNadzvjuVu_EoKHHDbvunPzmJ2",
      "channelname": "Rangoli - Topic",
      "imageURL": ""
    },
    {
      "playlistname": "Popular Videos - Rangoli & Peafowl",
      "playlistid": "PLxE-NIHKNadxA5IAylBprcVUPYJNHaPaK",
      "channelname": "Rangoli - Topic",
      "imageURL": ""
    },
    {
      "playlistname": "Popular Thai Pongal & Kolam videos",
      "playlistid": "PLcIFZKKK5Ex29vy7lbWKbFstgoeG1XNCP",
      "channelname": "Thai Pongal - Topic",
      "imageURL": ""
    },
    {
      "playlistname": "aanmeegam / ????????",
      "playlistid": "PLCR_lidRFmjCnNhVRCRTENHZ360ySzTHH",
      "channelname": "Zio Tamil",
      "imageURL": ""
    },
    {
      "playlistname": "kolangal",
      "playlistid": "PL3CPcT90G7vPDD5Iw1A5FLNEMA_RXSoHY",
      "channelname": "LEARNGOODALL",
      "imageURL": ""
    },
    {
      "playlistname": "108 simple Diwali kolam designs ( 4 to 9 dots ) | an easy rangoli a day to learn for Diwali decoration ideas | simple New Year rangoli",
      "playlistid": "PLwHuVZQFx6IhZ-8HtC5umsnyNxFGGwfXt",
      "channelname": "Sudha Balaji",
      "imageURL": ""
    }
  ],
  "success": true
}

任何一个人都有助于解决此错误。 提前谢谢!!!

1 个答案:

答案 0 :(得分:1)

  1. 检查连接中的字符集:(首选将其放在connection.php中)

    header( 'Content-Type: text/html; charset=utf-8' );
    include('connection.php');
    
    // Change character set to utf8
    mysqli_set_charset($con,"utf8");
    
    $query = "SELECT * FROM DevotionalCollection";
    $fetch=mysqli_query($con, $query ) or die(mysqli_error($con));
    
    if (mysqli_num_rows($fetch) > 0) {
        $response["data"] = array();
        while ($row = mysqli_fetch_array($fetch)) {
    
            $data = array();
            $data["playlistname"] = $row["playlistname"];
            $data["playlistid"] = $row["playlistid"];
            $data["channelname"] = $row["channelname"];
            $data["imageURL"] = $row["imageURL"];
    
            //$response["data"] = array();
            array_push($response["data"], $data);
    
        }
        header('Content-type: text/json');
        $response["success"] = TRUE;
        // echoing JSON response
        echo json_encode($response);
    }else {
        // no products found
        $response["success"] = FALSE;
        $response["message"] = "No data found";
    
        // echo no users JSON
        echo json_encode($response);
    }
    
    ?>
    
  2. 更改数据库中的字符集:

    ALTER DATABASE DBNAME CHARACTER SET utf8 COLLATE utf8_general_ci;