PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, December 4, 2022

[FIXED] How to Remove Double Quotes in Json Response

 December 04, 2022     codeigniter-3, json, jsonencoder, model-view-controller     No comments   

Issue

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

Solution

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


Answered By - Madhuri Patel
Answer Checked By - Senaida (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing