簡體   English   中英

無法在json中獲取我的js數組

[英]Can't get my js array in 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的遞歸中),結果我只會得到空括號...

那個怎么樣?

Probablu錯誤在這里

var account_to_rec = new Array();

然后您嘗試將其用作對象

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

account_to_rec [property_name] = $(this).html();

也許

 var account_to_rec = {};

???

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM