php到json结构

php到json结构,php,jquery,json,Php,Jquery,Json,我很难将php数组转换为json对象 Array( [28] => Array( [0] => Array( [0] => 1 [1] => 5 ) [1] => Array( [0] => 1 [1] => 18 ) [424] => Array(

我很难将php数组转换为json对象

Array(
    [28] => Array(
        [0] => Array(
            [0] => 1
            [1] => 5
        ) 
        [1] => Array(
            [0] => 1 
            [1] => 18
        )
        [424] => Array(
            [0] => Array(
                [0] => 1
                [1] => 5
            ) 
            [1] => Array(
                [0] => 1
                [1] => 18
            )
        )
     )
)
在jQuery中对这个结构进行json_编码之后,我使用了.each并获得了两个数组,但我似乎无法获取[28]和[424]。有什么想法吗

$.each(data, function(i, val) {
    console.log(val); // NAME ??
    console.log(data[i][0]); // LIST 1
    console.log(data[i][1]); // LIST 2
});

JSON将键编码为字符串,这意味着jQuery查找的是字符串,而不是整数。尝试使用字符串访问数组。

JSON将键编码为字符串,这意味着jQuery正在查找字符串,而不是整数。尝试使用字符串访问数组。

试试这个

$.each(data, function(i, val) {
    console.log(i); // name
    console.log(val); //array
});
$.each(data, function(i, val) {
    //First iterration "this" will point to '28' array
    //Second iterration "this" will point to '424' array

    //You can use it like this, this[i][0]

});
试试这个

$.each(data, function(i, val) {
    //First iterration "this" will point to '28' array
    //Second iterration "this" will point to '424' array

    //You can use it like this, this[i][0]

});

PHP数组键
28
424
将在回调函数内的javascript变量
i
中表示


检查文档,他们会详细解释。

PHP数组键
28
424
将在回调函数内的javascript变量
i
中表示


检查文档,他们会详细解释。

什么是
console.log(i)
yield?什么是
console.log(i)
yield?
json\u encode
(没有给出标志)将数组键编码为对象成员名,而不是数组键。
json\u encode
(没有给出标志)将数组键编码为对象成员名,不是数组键。很简单,示例使用“i”,我一直假设它是一个整数。谢谢很简单,示例中使用了“i”,我一直假设它是一个整数。谢谢