I have this issue. I want to iterate through the attributes of a JSON structure, i.e this structure
var txt = '{"employees":{' +
'"p1":{'+
'"info":{'+
'"firstName":"John","lastName":"Doe" }},' +
'"p2":{'+
'"info":{'+
'"firstName":"Anna","lastName":"Smith" }},' +
'"p3":{'+
'"info":{'+
'"firstName":"Peter","lastName":"Jones" }}'+
'}}';
I dont want to do something like
json.employees.p1.info.firstName;
(using the p1) I want to do something like
for(var i = 0; i<3;++i){
console.log(json.employees.p[i].info.firstName);
}
Does someone know how to do it?
I want to do that because the attribute p can be N not so I can't do p1, p2, p3, p4, ..., p101