小编Mac*_*ria的帖子

在php中将json字符串转换为整数

我正在使用 xampp,即使我在我的表中将 id 列设置为整数,输出仍然是字符串,即我得到"id":"1"而不是"id":1. 我遇到了一个可能的解决方案,JSON_NUMERIC_CHECK但我不知道如何在我的 php 脚本中实现它。有人可以告诉我如何修改我的 php 脚本,以便将 id 输出作为整数。

    <?php


    require("config.inc.php");
    $query_params=null;



    $query = "Select * FROM feeds";


    try {
        $stmt   = $db->prepare($query);
        $result = $stmt->execute($query_params);
    }
    catch (PDOException $ex) {
        $response["success"] = 0;
        $response["message"] = "Database Error!";
        die(json_encode($response));
    }


    $rows = $stmt->fetchAll();


    if ($rows) {
        $response["feed"]   = array();

        foreach ($rows as $row) {
            $post             = array();
            $post["id"] = $row["id"];
            $post["name"]    = $row["name"];
            $post["image"]  = $row["image"];

            array_push($response["feed"], $post);
        }


        echo json_encode($response);


    } …
Run Code Online (Sandbox Code Playgroud)

php string int

2
推荐指数
1
解决办法
5189
查看次数

标签 统计

int ×1

php ×1

string ×1