我有一个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