这是我的功能:
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/