Looping JSON object JavaScript
This question already has an answer here:
// 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];
}
Long numbers are keys in your json. You can loop through keys using Object.keys() function:
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/52012.html
上一篇: 引用/分析对象
下一篇: 循环JSON对象JavaScript