How to Remove Double Quotes in Json Response

474 views Asked by At

My Code Having Json Response Like this

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

Need Like This

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

For this I have done codeigniter

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

This Response is

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

There are 1 answers

5
Madhuri Patel On BEST ANSWER

Add JSON_NUMERIC_CHECK (integer) when encode in json.

JSON_NUMERIC_CHECK (integer) : Encodes numeric strings as numbers

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