2016-07-16 58 views
-2

我的數組:如何保存多維pseudoArray到localStorage的

state = [ 
[ "depth":0, 
    "id":1, 
    "desc":"something", 
    "prof": [ 
    ["ID":1, "ID_ZASOB":1], 
    ["ID":5, "ID_ZASOB":4] 
    ] 
], 
[ "depth":2, 
    "id":3, 
    "desc":"somethingOther", 
    "prof": [ 
    ["ID":2, "ID_ZASOB":5], 
    ["ID":2, "ID_ZASOB":1] 
    ] 
], 
] 

我不得不將其存儲在localStorage的。

我試過json.stringify,但這不是一個對象,它是一個數組,

+3

_「但這不是一個對象,它是一個數組」_不,它是一個語法錯誤 – Andreas

回答

2

這是在混合陣列,對象 的磁盤陣列不能有鑰匙

state = [ 
{ "depth":0, 
    "id":1, 
    "desc":"something", 
    "prof": [ 
    {"ID":1, "ID_ZASOB":1}, 
    {"ID":5, "ID_ZASOB":4} 
    ] 
}, 
{ "depth":2, 
    "id":3, 
    "desc":"somethingOther", 
    "prof": [ 
    {"ID":2, "ID_ZASOB":5}, 
    {"ID":2, "ID_ZASOB":1} 
    ] 
} 
] 
寫arrays.You的不正確的方法

現在你可以將它串聯起來