Php ajax数据是字符串而不是数组

Php ajax数据是字符串而不是数组,php,jquery,ajax,Php,Jquery,Ajax,我使用jQueryAjax将一些数据发送到php文件 $.ajax({ type: 'GET', url: 'dosomething.php', data: {list:orderNew} }); 这是发送给php的 $list = $_GET['list']; print$list为我提供了以下信息: list[4]=null&list[1]=null&list[2]=4&a

我使用jQueryAjax将一些数据发送到php文件

$.ajax({
            type: 'GET',
            url: 'dosomething.php',
            data: {list:orderNew}
            });
这是发送给php的

$list = $_GET['list'];
print$list为我提供了以下信息:

  list[4]=null&list[1]=null&list[2]=4&list[12]=null&list[11]=null&list[3]=null
我希望将其作为一个数组,这样我就可以在我的php文件中执行此操作

 foreach($list as $key => $value) {
            if($value == "null"){
                $value = 0;
            }
}

a如何将列表[]数据作为实际数组发送,以便php将其作为数组读取,或将字符串转换为数组,以便我可以在php页面上执行foreach操作?

您必须在服务器端使用JSONECODE,然后在jn客户端:

$.ajax({
            type: 'JSON',
            url: 'dosomething.php',
            data: {list:orderNew}
            });
试一试

输出

Array
(
    [list] => Array
        (
            [4] => null
            [1] => null
            [2] => 4
            [12] => null
            [11] => null
            [3] => null
        )

)

。如果我将类型更改为JSON,则使用什么作为我的php?这用于修改服务器返回的内容,与发送到服务器的内容无关。它在语法上也是不正确的,因为type:应该是“POST”或“GET”(或任何其他有效的类型),您可能是指
dataType
ok,那么如何让我的php foreach现在工作,这样我就可以得到$key和$value呢?使用
foreach($arr['list']as$key=>$value){
Array
(
    [list] => Array
        (
            [4] => null
            [1] => null
            [2] => 4
            [12] => null
            [11] => null
            [3] => null
        )

)