嗨,我想做一个http://api.androidhive.info/json/movies.json之类的json输出
我在php中编写此代码:

<?php
    header('Content-Type: application/json');
    $con=mysqli_connect("localhost","root","","ebrahim");
    $sql="SELECT * FROM film";
    $result=mysqli_query($con,$sql);
    $response= array();
    while($row=mysqli_fetch_array($result,MYSQLI_NUM))
    {
        $product = array();
        $product["title"]=$row[1];
        $product["image"]=$row[2];
        $product["rating"]=$row[3];
        $product["releaseyear"]=$row[4];
        $product["genre"]=array($row[5],"salam");
        array_push($response,$product);
    }
    echo json_encode($response, JSON_PRETTY_PRINT);
?>


但是在我的json输出评级中,不是double值是字符串值,releaseyear不是int值是字符串值,并且我的url图像带有反斜杠。您可以在这张图片中看到它。
在我的mysql表中评级是double并且releaseyear是int
enter image description here

这是我的mysql表
[在此处输入图片描述] [2]

请帮助我。

最佳答案

检查this答案。您可以使用以下命令显式强制类型:

$product["rating"]=(float)$row[3];

07-24 09:46
查看更多