Vinoth Smart
Vinoth Smart

Reputation: 403

How to Remove Double Quotes in Json Response

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"]

Upvotes: 0

Views: 480

Answers (1)

Madhuri Patel
Madhuri Patel

Reputation: 1270

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);

Upvotes: 1

Related Questions