【发布时间】:2011-08-01 00:04:12
【问题描述】:
我正在使用一些类似于以下内容的 Json:
{
"Apps" : [
{
"Name" : "app1",
"id" : "1",
"groups" : [
{ "id" : "1", "name" : "test group 1", "desc" : "this is a test group" },
{ "id" : "2", "name" : "test group 2", "desc" : "this is another test group" }
]
}
]
}
如果我在 jquery 中解析它以返回一个对象,并且我正在像这样迭代应用程序:
$.each(myJsonObject.Apps, function() { ... };
如何获取this.groups 的长度?
我试过了
- this.groups.length
- this.groups.length()
- $(this).groups.length()
我找不到任何关于具有良好信息的多层 json 对象的体面文档。
任何链接或示例或建议将不胜感激。
【问题讨论】:
-
这不只是一个错字吗? JSON 中的
groups全部小写,但您的代码示例有Groups。 -
即使在正确的情况下它也不起作用。生病更新我的例子
-
你确定吗?当我在控制台中尝试时它工作正常。
-
试试 $(var.Apps[0].groups).length