如何使用ExtJS获取/列出JSON数据的所有字段名称?

时间:2011-09-10 09:27:28

标签: json extjs

我有这个json数据:

[
{"ID":"1","name":"google","IP":"69.5.33.22","active":"true"},
{"ID":"2","name":"bing","IP":"70.5.232.33","active":"false"}
]

我想获取所有属性名称(?),例如:

名,ID,IP,活性

注意:我不介意google,70.5.232.33等“name”和“IP”的内容。只是,我想自己获取字段。

2 个答案:

答案 0 :(得分:2)

var jsonString = [
    {"ID":"1","name":"google","IP":"69.5.33.22","active":"true"},
    {"ID":"2","name":"bing","IP":"70.5.232.33","active":"false"}
];
var keyArray = Ext.Object.getKeys(Ext.JSON.decode(jsonString));
console.log(keyArray) // ["ID","name","IP","active"]

答案 1 :(得分:1)

在解析完对象后迭代它。

js> for(i in {"ID":"1","name":"google","IP":"69.5.33.22","active":"true"})
{
  print(i);
}
ID
name
IP
active
js>