can anyone give me a correct solution for this program.how to print all values using foreach loop.I tried but I got an error as undefined values Thanks in advance...I am waiting for reply...
differ.json:
{
"table":
[
{
"place":
{
"STATE":"TAMILNADU",
"DISTRICT":"VELLORE"
}
},
{
"place":
{
"STATE":"KERALA",
"DISTRICT":"ALAPHUZHA"
}
},
{
"place":
{
"STATE":"ANDHRA PRAADESH",
"DISTRICT":"KUNTUR"
}
}
]
}
Nodejs file:
var fs = require('fs');
var obj1 = fs.readFileSync('differ.json', 'utf8');
var data=JSON.parse(obj1);
var countobjects = Object.keys(data).length;
console.log(countobjects);
for( var place in data.table)
{
for( var field in data.table[place])
{
console.log("State:" + data.table[place].field);
console.log("District:" + data.table[place].field);
}
}