Reputation: 1199
I have php array as bellow
$php_arr = json_encode(array('1'=>'"data1', '1'=>'data2'));
that json object i try to access inside Extjs as bellow
var test = Ext.JSON.decode()(<?php echo $php_arr; ?>);
but that gave to me error as
Uncaught Ext.JSON.decode(): You're trying to decode an invalid JSON String:
because of JSON object break "data1
How can I get this JSON object decoded in ExtJs without lose "?
Upvotes: 0
Views: 695
Reputation: 77522
Try this
var test = Ext.JSON.decode(<?php echo $php_arr; ?>);
and you must escape "
like so
$php_arr = json_encode(array('1'=>'\"data1', '2'=>'data2'));
Also in PHP you can use addslashes, like so
$php_arr = json_encode(array('1'=>'"data1', '2'=>'data2'));
$php_arr = addslashes($php_arr);
Upvotes: 2