dongye9991 2016-06-21 14:02
浏览 84

为什么我的php没有返回正确的json? (“期待UTF-8,UTF-16或UTF-32”)

I am having trouble using Alamofire in iOS because because my php seems to not be returning valid json. I have added the header "header("Content-Type: application/json; charset=utf-8");" before encoding array but it still does not work. If it matters some columns in my database table are encoding using utf8mb4_unicode_ci. Here is my php:

<?php
    $con = mysqli_connect("localhost","hide","hide","hide");
    mysqli_set_charset($con, "utf8");

    if(mysqli_connect_errno())
    {
        echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }

    $sql = "SELECT * FROM Business";

    if($result = mysqli_query($con, $sql))
    {
        $resultArray = array();
        $tempArray = array();

        while($row = $result->fetch_object())
        {
            $tempArray = $row;
            array_push($resultArray, $tempArray);
        }

        header("Content-Type: application/json; charset=utf-8");
        echo json_encode($resultArray);
    }

    mysqli_close($result);
    mysqli_close($con);
?>

Unformatted json:

[{"business_id":"0","imageURL":"imageUrl","shortDescription":"shortDescription","longDescription":"longDescription","price":"price","specialText":"specialText","order_rank":"1"}]

Here is formatted json specifying error:

enter image description here

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 保护模式-系统加载-段寄存器
    • ¥15 电脑桌面设定一个区域禁止鼠标操作
    • ¥15 求NPF226060磁芯的详细资料