代码之家  ›  专栏  ›  技术社区  ›  Vinoth Smart

如何在Json响应中删除双引号

  •  0
  • Vinoth Smart  · 技术社区  · 6 年前

    我的代码有如下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 回复  |  直到 6 年前
        1
  •  1
  •   Madhuri Patel    6 年前

    添加 当用json编码时。

    :将数字字符串编码为数字

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