Removing quotes from a JSON encoded string

Currently, I have a JSON encoded string generated by entering values ​​from an array, it looks like this:

"["{value: 97049}","{value: 84866}","{value: 39402}","{value: 30250}","{value: 33363}"]"

I need to convert it to the following format:

"[{value: 97049},{value: 84866},{value: 39402},{value: 30250},{value: 33363}]"

Thank.

+3
source share
4 answers
$input = $json_var;

$input = str_replace( '"', '', $input ); // strip em
$input = '"' . $input . '"'; // wrap back around
+3
source

JS:

var json_array = JSON.parse(json_string);
for (var i = 0; i < json_array.length; i++) {
    json_array[i] = JSON.parse(json_array[i];
}

PHP:

$json_array = json_decode($json_string);
$json_array = array_map('json_decode', $json_array);

It would probably be better to fix this in the source. If it should be an array of objects, do not specify each element of the array before adding them to the array.

+2
source
var myQuotedJson = '"["{value: 97049}","{value: 84866}","{value: 39402}","{value: 30250}","{value: 33363}"]"';

var myUnquotedJson = myQuotedJson.replace(/"/, '');
0
source

You can do it like this:

var input = '"["{value: 97049}","{value: 84866}","{value: 39402}","{value: 30250}","{value: 33363}"]"';
 output = '"' + input.replace('"','') + '"';
 //Alerts your output
 alert(output );
0
source

All Articles