0

我的代码有这样的 Json 响应

["0","0","0","0","0","0","204.4"]

需要这样

[ 0, 0, 0, 0, 0, 0, 204.4 ]

为此我已经完成了codeigniter

$query = $this->db->query($selectQuery);
    $totalInvoice = array();
    foreach ($query->result() as $row)
    {
        $totalInvoice[] = $row->total;
    }
    print_r(json_encode($totalInvoice));

这个回应是

["0","0","0","0","0","0","204.4"]
4

1 回答 1

1

在 json 中编码时添加 JSON_NUMERIC_CHECK(整数) 。

JSON_NUMERIC_CHECK (integer) : 将数字字符串编码为数字

$query = $this->db->query($selectQuery);
    $totalInvoice = array();
    foreach ($query->result() as $row)
    {
        $totalInvoice[] = $row->total;
    }
    print_r(json_encode($totalInvoice, JSON_NUMERIC_CHECK);
于 2018-11-28T12:40:48.767 回答