如何在Json Response中删除双引号

时间:2018-11-28 12:35:00

标签: json model-view-controller codeigniter-3 jsonencoder

我的代码具有这样的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"]

1 个答案:

答案 0 :(得分:1)

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

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

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