javascript - 无法获取 json 中的 js 数组

标签 javascript jquery json

这是我的功能:

function browsepage_from(starting_node)
{
    //record the properties of the object
    var account_to_rec = new Array();
    var property_name
    var properties = $(starting_node).children('div').children("p").each(function(){
        property_name = $(this).attr('class').split(' ')[1];
        account_to_rec[property_name] = $(this).html();

    });
    //push the object with properties newly created into a global variable

    to_save.push(account_to_rec);

    //check if children
    if($(starting_node).children('ul'))
    {
        $(starting_node).children('ul').children("li").each(function(){
            browsepage_from($(this))

        });
    }
    else
    {

    }

}

没什么特别的...

to_save 是一个全局变量:

 to_save = new Array();

但是在控制台中我的数组看起来像这样:

[[]


account_action
        "none"

account_code
        "000000"
bla bla

[]


account_action
        "none"

account_code
        "600000"
bla bla

]

如果我使用 JSON.stringify (在完成的 to_save 上或在每个 account_to_rec 的递归中),我只会得到空括号......

怎么样?

最佳答案

此处可能出现错误

var account_to_rec = new Array();

然后你尝试将它用作对象

property_name = $(this).attr('class').split(' ')[1];

account_to_rec[属性名称] = $(this).html();

也许

 var account_to_rec = {};

???

关于javascript - 无法获取 json 中的 js 数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22699231/

相关文章:

javascript - 如何访问Json数据?

javascript - 在不同的列中显示 JSON 结果 Angular JS

javascript - 两个 Pane (div)的统一滚动条

jquery - 如何在 IE 和 firefox 中处理没有空格的长句

javascript - Angular 和 ASP.NET MVC - 后端收到时参数为空

javascript - 为什么我不能将事件添加到引用自身的集合中的每个元素而不是 "for(){}"语句中的最后一个元素

javascript - jQuery Accordion - 缺少什么?

javascript - jquery中如何将div的值分配给没有id和class的未命名文本框

java.lang.RuntimeException : Unable to start activity ComponentInfo in Android

PHP JSON 编码方括号