循环JSON对象JavaScript
这个问题在这里已经有了答案:
// data is all the json you gave in the example
for(var key in data){
// keys are the numbers
// and inner are the objects with message and subject
var inner = data[key];
}
长号码是你的JSON中的关键。 您可以使用Object.keys()函数循环访问键:
var data = {
'1457458375537': {
'message': 'this is the message',
'subject': 'my subject'
},
'1457467436271': {
'message': 'test message',
'subject': 'hello'
}
};
Object.keys(data).forEach(function(key) {
console.log(key); // prints property name - long number
console.log(data[key].message);
console.log(data[key].subject);
});
链接地址: http://www.djcxy.com/p/52011.html