如何将数据存储到json对象中

时间:2015-06-16 05:16:17

标签: jquery json

我用对象传递数组。然后,这些数据必须存储在对象内的数组。

我这样过去了。

response.resp = [...]
insertBranch("one", response.resp);

所以,在那个方法中,

function insertBranch(name,info){
    this.jfsInfo.branches[name] = info;
}

它必须像

jfsInfo.branches= {
"one":[...]
}

如果我通过

insertBranch("two", response.resp);

它自动创建了两个对象,并且该数组必须存储在该对象中。

1 个答案:

答案 0 :(得分:0)

看一下这段代码,它可以帮到你

<script>
var a = [1,2,3, 'a', 'b'];
    var jfsInfo={};
    insertBranch("two", a);
    function insertBranch(value, array)
    {
        if(value=="one")
        {
            jfsInfo.branches={};
            jfsInfo.branches.one=array;
        }
        else if(value=="two")
        {
           jfsInfo.branches={};
           jfsInfo.branches.one=array;
           jfsInfo.branches.two=array;
        }
    }

    console.log(jfsInfo.branches);

</script>
相关问题