PHP 数组 JSON 编码,对象在 ExtJs 中解码
PHP array JSON encode and that object decode inside ExtJs
我有 php 数组如下
$php_arr = json_encode(array('1'=>'"data1', '1'=>'data2'));
我尝试在 Extjs 中访问的 json 对象如下所示
var test = Ext.JSON.decode()(<?php echo $php_arr; ?>);
但这给了我一个错误
Uncaught Ext.JSON.decode(): You're trying to decode an invalid JSON String:
因为 JSON 对象损坏 "data1
如何在 ExtJs 中解码这个 JSON 对象而不丢失 "?
试试这个
var test = Ext.JSON.decode(<?php echo $php_arr; ?>);
而你必须像这样逃脱"
$php_arr = json_encode(array('1'=>'\"data1', '2'=>'data2'));
也可以在 PHP 中使用 addslashes,像这样
$php_arr = json_encode(array('1'=>'"data1', '2'=>'data2'));
$php_arr = addslashes($php_arr);
我有 php 数组如下
$php_arr = json_encode(array('1'=>'"data1', '1'=>'data2'));
我尝试在 Extjs 中访问的 json 对象如下所示
var test = Ext.JSON.decode()(<?php echo $php_arr; ?>);
但这给了我一个错误
Uncaught Ext.JSON.decode(): You're trying to decode an invalid JSON String:
因为 JSON 对象损坏 "data1
如何在 ExtJs 中解码这个 JSON 对象而不丢失 "?
试试这个
var test = Ext.JSON.decode(<?php echo $php_arr; ?>);
而你必须像这样逃脱"
$php_arr = json_encode(array('1'=>'\"data1', '2'=>'data2'));
也可以在 PHP 中使用 addslashes,像这样
$php_arr = json_encode(array('1'=>'"data1', '2'=>'data2'));
$php_arr = addslashes($php_arr);