我有一个curl语句,它将json格式化的数组拖到php中。然后,我希望将这个数组传输到jQuery,以便客户端能够保存该数组。我目前正在使用以下方法:
<script>var obj = jQuery.parseJSON( <?php echo var_dump($json_short); ?> );</script>客户看到的情况如下:
<script>var obj = jQuery.parseJSON( array(1) {
["search"]=>
array(50) {
[0]=>
array(6) {
["id"]=>
string(6) "641279"
["description"]=>
string(36) "Instyle - Responsive Portfolio Theme"
["url"]=>
string(69) "http://themeforest.net/item/instyle-responsive-portfolio-theme/641279"
["type"]=>
string(9) "wordpress"
["sales"]=>
string(3) "135"
["rating"]=>
string(3) "4.5"
}
....
}
}
);</script>现在,obj会保存数组吗?这是正确的方法吗?因为我遇到了一个错误:
Uncaught SyntaxError: Unexpected token { 发布于 2014-02-06 15:11:39
发布于 2014-02-06 15:11:21
不能使用直接转储,首先需要json_encode:
<script>var obj = <?php echo json_encode($json_short) ?>;</script>
发布于 2014-02-06 15:13:31
我不明白你在用<script>var obj = jQuery.parseJSON( <?php echo var_dump($json_short); ?> );</script>做什么
在PHP中尝试echo json_encode($json_short);
https://stackoverflow.com/questions/21606524
复制相似问题