Remove double quote in json_encode()

I want remove double quote in my json_encode, that is my code:


require_once '';
//## Clase Base de Datos
require_once 'Database.class.php';
//## Obtengo los parametros pasados por el metodo GET
$params = $_REQUEST;


$result = mysql_query("SELECT * from ranking WHERE posicion BETWEEN     ".$params['pos_ini']." AND ".$params['pos_fi']) or die('Could not query');

    $filas = mysql_num_rows($result);
    $columnas = mysql_num_fields($result);

        $fila_dato = mysql_fetch_assoc($result);
                    $campo = mysql_field_name($result,$k);
                    $campo = str_replace('\"', '', $campo);
                    $array_json[$i][$campo] = $fila_dato[$campo];
    $array_final = json_encode($array_json);
    $array_final = preg_replace('/"([a-zA-Z]+[a-zA-Z0-9]*)":/','$1:',$array_final);
    echo $array_final;
} else {
    echo '[]';

My result is that:


I want to remove double quote of "id_posiciones" and "device_version" too.

How can I do for the result is that:



If you add an underscore to your regex at the end it will do it.

$array_final = preg_replace('/"([a-zA-Z]+[a-zA-Z0-9_]*)":/','$1:',$array_final);

I assume that's what that preg_replace is for anyway.

You can use this bellow code to remove quote from numeric value.

It will work >=PHP 5.3.

$encoded = json_encode($data, JSON_NUMERIC_CHECK);

Replace this line:

 $array_final = preg_replace('/"([a-zA-Z]+[a-zA-Z0-9]*)":/','$1:',$array_final);


$array_final = preg_replace('/"([a-zA-Z_]+[a-zA-Z0-9_]*)":/','$1:',$array_final);

Note that the regex class [a-zA-Z] does not match the '_'

You can use $.parseJSON to parse the string and create a Javascript object from it, or better yet use a method like $.getJSON to get it

// use can use addslashes() function for storing in mysql database 
// or remove  slashes  u can use stripslashes() function.

$json_array = array(
'title' => 'Example string\'s with "special" characters'

echo $json_decode =addslashes(json_encode($json_array));

output-{\"title\":\"Example string\'s with \\\"special\\\" characters\"}

Need Your Help

Initializing a std::map when the size is known in advance

c++ dictionary std

I would like to initialize a std::map. For now I am using ::insert but I feel I am wasting some computational time since I already know the size I want to allocate. Is there a way to allocate a fixed

Eclipse Axis error when creating web service

java eclipse web-services axis

Every time I try to create a new Web Service in Eclipse, I get this error: