2011-09-10 69 views
1

我有這樣的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,活躍

注:我不知道介意「名稱」和「IP」中有什麼,例如google,70.5.232.33等等。只是,我想要獲取字段本身。

回答

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

解析對象後迭代對象。

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