2013-08-07 18 views
0

我很難找到JSON.stringify的錯誤。很難找到JSON.stringify bug:不要解析數組

我有具有以下結構的對象:

var test_object = { 
    id : 0, 
    type: 'root', 

    related_dropzone_id : 0, 
    related_dropzone_order: 0, 

    options : {}, 
    children: [] 
} 

其中children是定義爲test_object就像對象的數組:

[ 
     12387192837: test_object_a, 
     12387192838: test_object_b 
] 
當然

,具有用於它的屬性不同的值。

當我做一個console.log(top_most_object),控制檯拋出正確的對象,其屬性嵌套,但是當我輸出一個console.log(JSON.stringify(top_most_object))然後它示出了具有最上面的children數組作爲空字符串:[]又名:截斷。

JSON.stringify的調用不會拋出任何錯誤,所以我不知道這是什麼問題。

所以問題是,我怎樣才能在這裏調試問題?

回答

1

您缺少對象的括號。

[ 
     {12387192837: test_object_a}, 
     {12387192838: test_object_b} 
] 

Other than that the stringify works for me

+0

哦哦boyyy !!! Yeahhhh !!!! :D感謝您的快速回答,指出我走了正確的道路!問題在於我將'children'定義爲'array'而不是'object',這是爲了訪問諸如'children [12387192837]'這樣的內部屬性所需的行爲。似乎在某些時候,我將它的聲明更改爲'children:[]'from'children:{}',但沒有注意到它:(:(我需要一杯咖啡或者去睡覺)。再次感謝! – diosney

+0

Ah ok yeah –

+0

另一方面,我真的不知道爲什麼控制檯沒有拋出一個錯誤0-0 – diosney