开发者

get JSON object attribute name

I know that I can retrieve "session" by using item.fields.name but what if I don't know in advance that the attribute is called "name". How can I retrieve the list of the attributes names in fields first.

[
    {
        "pk": 2,
        "model": "auth.group",
        "fields": {
开发者_JAVA技巧            "name": "session"
        }
    }
]


You can convert it to a javascript object, then iterate over the properties:

  eval("var object = " + that_json_thing);
  for (property in object) {
    alert(property);
  }

There is probably a "more correct" way of doing it, but this demonstrates the basic idea.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜