无法在php中获取json数组

无法在php中获取json数组,php,json,Php,Json,我在ajax请求中传递json,但每次都返回10,为什么 我的阵型有什么不及格的 这是我的密码: jQuery(document).ready(function($){ $('#list-3 .ajaxcall').click(function(){ $.ajax({ type : "GET", url : ajaxurl, dataType: 'json', contentT

我在ajax请求中传递json,但每次都返回10,为什么

我的阵型有什么不及格的

这是我的密码:

jQuery(document).ready(function($){
    $('#list-3 .ajaxcall').click(function(){
        $.ajax({
            type : "GET",
            url : ajaxurl,
            dataType: 'json',
            contentType: "application/json; charset=utf-8",
            data : { 
                    gpl_args : JSON.stringify({"cat":"26","posts_per_page":"4","paged":1}),
                    gpl_layout : {"show_thumb":"1","columns":"4","thumb_height":"85","thumb_width":"85","title_link":"1","content_excerpt":"50","posts_per_page":"4"}
            },
            success : function(response) {
                // The server has finished executing PHP and has returned something,
                // so display it!
                $("#list-3").append(response);
            }
        });
    });
}); 
以及:

更新:

my data inside ajax:
   data    : { gpl_args : JSON.stringify(<?php echo json_encode($args); ?>),
              JSON.stringify(gpl_layout   : <?php echo json_encode($layout); ?>)},
ajax中的我的数据:
数据:{gpl_args:JSON.stringify(),
JSON.stringify(gpl_布局:)},

是否打印isset()的布尔结果而不是实际的参数?

简单修复。您必须对json进行反编码,而不是对其进行EN编码

$args = isset($_REQUEST['gpl_args']) ? $_REQUEST['gpl_args'] : null;
$args = json_decode(stripslashes($args));
print_r($args)

查看您的php脚本:

$args       = isset($_REQUEST['gpl_args']);
//$args     = json_encode(isset($_REQUEST['gpl_args'])); 
// $args is false(Boolean type), But not json
print_r($args);  // print_r(false);  is show nothing!!
$json_array[] = isset($_REQUEST['gpl_args']) ? $_REQUEST['gpl_args'] : false;
echo json_encode($json_array);  // will show json string
正确的方法:

$args       = isset($_REQUEST['gpl_args']);
//$args     = json_encode(isset($_REQUEST['gpl_args'])); 
// $args is false(Boolean type), But not json
print_r($args);  // print_r(false);  is show nothing!!
$json_array[] = isset($_REQUEST['gpl_args']) ? $_REQUEST['gpl_args'] : false;
echo json_encode($json_array);  // will show json string

好吧,您没有返回有效的JSON请告诉我如何返回有效的JSON$args在这里是一个布尔值,而不是一个数组。尝试
die(json_编码(数组('args'=>$args))
我使用
die
确保脚本立即退出并仅输出JSON编码的文本,并确保我拥有有效的JSON。不,您使用的是返回布尔值的
isset
。您应该将此作为评论而不是答案发布。但现在我将
0
作为回报。我正在用我剩下的php代码更新我的问题。如果我不使用json解码,现在就得到结果,比如:
{“cat\”:“26\”,“每页发布”:“4\”,“paged\”:1}0
我明白了。。。首先,我在上面的示例中添加了
stripslashes()
,我们可以通过取消这一限制来解决这个问题。我是否需要最后使用
die()
exit()
?无需死亡或退出。干杯