我有一個JSON解析返回對象集。
{
"word":[
"offered",
"postings"
],
"annotation":[
["offered highlighted","this is also given as annotation","This annotation has been added here currently","offering new annotation points","\"offered\" is in the sense of languages"],
["my postings","this is new annotation for postings.","my postings","this is posting annotation.... Working for the feature of the annotation."]
],
"user":[
["","","vinoth","Anonymous","Vinoth"],
["Anonymous","vinoth","Anonymous","Arputharaj"]
],
"id":[
["58","60","61","63","68"],
["32","57","59","62"]
],
"comment":
{
"id58":["first comment","This is a old comment for this annotation","Next level of commenting.","Fourth comment to this annotation","testing"],
"id61":["this is an old annotation.\r\nMy comment is very bad about this.","Second comment to this annotation"],
"id57":["I want to add one more comment to this"]
},
"commentUser":{
"id58":["vinoth","Anonymous","Vinothkumar","Vinothkumar","vinoth"],
"id61":["Anonymous","Commentor"],
"id57":["vinoth"]
}
}
我想知道每個對象和數組的長度。我使用.length
來獲得annotation[0].length
的長度。我得到了預期的結果,即:5.對於「用戶」&「id」也是如此。
但我沒有收到「字」,「id58」,「id61」等的長度...... 此外,我想了解的comment
& commentUser
長度。
請幫我這個。
謝謝你這個答案。這適用於「評論」和「評論使用者」。但是「myObj.word.length」返回「undefined」 (myObj是我的對象)。 – 2010-08-02 08:15:36
@Vinothkumar Arputharaj - 假設'myObj'具有在你的示例代碼中給出的定義,那麼'myObj.word'是一個長度爲2的數組。如果你發現'myObj.word.length'是'undefined',那麼一部分你描述的情況是錯誤的。爲什麼不在瀏覽器中設置斷點並檢查數據?您可以在Firefox中使用Firebug或使用IE 8和Chrome的內置調試器來執行此操作。 – 2010-08-02 10:07:28
但是,我可以通過使用for循環來計算** myObj.word.length **的長度。 – 2010-08-02 10:24:24