How to get/list all field names of a JSON data with ExtJS?
I have this json data:
[
{"ID":"1","name":"google","IP":"69.5.33.22","active":"true"},
{"ID":"2","name":"bing","IP":"70.5.232.33","active":"false"}
]
I want to get the all property names (?), like:
name,I开发者_Python百科D,IP,active
Note: I don't mind what is there at "name" and "IP" like google, 70.5.232.33, etc. Just, I want to get the fields itself.
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"]
Iterate over the object after you've parsed it.
js> for(i in {"ID":"1","name":"google","IP":"69.5.33.22","active":"true"})
{
print(i);
}
ID
name
IP
active
js>
精彩评论