我有一个json对象,它有多个表,每个表有多列,我想访问所有表,然后是每个表中的所有列,这里是我的json对象中的一些示例数据..
{
"Table1": [{
"AColumn": "3123121288",
"BColumn": "\/Date(1449064218000+0500)\/",
"CColumn": "865342608608",
"DColumn": "12422008054140",
"EColumn": "Plot # 11-C, Bukhari Commercial Street-2, Phase-VI, DHA, Karachi.",
"FColumn": "67.058",
"GColumn": "67.058"
}, {
"AColumn": "3123121288",
"BColumn": "\/Date(1449064218000+0500)\/",
"CColumn": "865342608608",
"DColumn": "12422008054140",
"EColumn": "Plot # 11-C, Bukhari Commercial Street-2, Phase-VI, DHA, Karachi.",
"FColumn": "67.058",
"GColumn": "67.058"
}],
"Table2": [{
"AColumn": "3123121288",
"BColumn": "\/Date(1449064218000+0500)\/",
"CColumn": "865342608608",
"DColumn": "12422008054140",
"EColumn": "Plot # 11-C, Bukhari Commercial Street-2, Phase-VI, DHA, Karachi.",
"FColumn": "67.058",
"GColumn": "67.058"
}, {
"AColumn": "3123121288",
"BColumn": "\/Date(1449064218000+0500)\/",
"CColumn": "865342608608",
"DColumn": "12422008054140",
"EColumn": "Plot # 11-C, Bukhari Commercial Street-2, Phase-VI, DHA, Karachi.",
"FColumn": "67.058",
"GColumn": "67.058"
}],
"Table3": {
"AColumn": "3123121288",
"BColumn": "\/Date(1449064218000+0500)\/",
"CColumn": "865342608608",
"DColumn": "12422008054140",
"EColumn": "Plot # 11-C, Bukhari Commercial Street-2, Phase-VI, DHA, Karachi.",
"FColumn": "67.058",
"GColumn": "67.058"
},
{
"AColumn": "3123121288",
"BColumn": "\/Date(1449064218000+0500)\/",
"CColumn": "865342608608",
"DColumn": "12422008054140",
"EColumn": "Plot # 11-C, Bukhari Commercial Street-2, Phase-VI, DHA, Karachi.",
"FColumn": "67.058",
"GColumn": "67.058"
}],
}
答案 0 :(得分:0)
var obj = {
"Table1": [{
"AColumn": "3123121288",
"BColumn": "\/Date(1449064218000+0500)\/",
"CColumn": "865342608608",
"DColumn": "12422008054140",
"EColumn": "Plot # 11-C, Bukhari Commercial Street-2, Phase-VI, DHA, Karachi.",
"FColumn": "67.058",
"GColumn": "67.058"
}, {
"AColumn": "3123121288",
"BColumn": "\/Date(1449064218000+0500)\/",
"CColumn": "865342608608",
"DColumn": "12422008054140",
"EColumn": "Plot # 11-C, Bukhari Commercial Street-2, Phase-VI, DHA, Karachi.",
"FColumn": "67.058",
"GColumn": "67.058"
}],
"Table2": [{
"AColumn": "3123121288",
"BColumn": "\/Date(1449064218000+0500)\/",
"CColumn": "865342608608",
"DColumn": "12422008054140",
"EColumn": "Plot # 11-C, Bukhari Commercial Street-2, Phase-VI, DHA, Karachi.",
"FColumn": "67.058",
"GColumn": "67.058"
}, {
"AColumn": "3123121288",
"BColumn": "\/Date(1449064218000+0500)\/",
"CColumn": "865342608608",
"DColumn": "12422008054140",
"EColumn": "Plot # 11-C, Bukhari Commercial Street-2, Phase-VI, DHA, Karachi.",
"FColumn": "67.058",
"GColumn": "67.058"
}],
"Table3": [{
"AColumn": "3123121288",
"BColumn": "\/Date(1449064218000+0500)\/",
"CColumn": "865342608608",
"DColumn": "12422008054140",
"EColumn": "Plot # 11-C, Bukhari Commercial Street-2, Phase-VI, DHA, Karachi.",
"FColumn": "67.058",
"GColumn": "67.058"
},
{
"AColumn": "3123121288",
"BColumn": "\/Date(1449064218000+0500)\/",
"CColumn": "865342608608",
"DColumn": "12422008054140",
"EColumn": "Plot # 11-C, Bukhari Commercial Street-2, Phase-VI, DHA, Karachi.",
"FColumn": "67.058",
"GColumn": "67.058"
}]
}
for (var table in obj) {
document.write('<table><thead>')
for (var columns in obj[table][0]) {
document.write('<th>'+columns+'</th>')
}
document.write('</thead>')
for (var i=0;i<obj[table].length;i++) {
var row = obj[table][i];
document.write('<tr>');
for (var columns in row) {
document.write('<td>'+row[columns]+'</td>')
}
document.write('</tr>');
}
document.write('</table>')
}
table, td { border:1px solid black}
答案 1 :(得分:0)
var result =[];
var jsonObj = yourJsonObject;
for (var key in jsonObj){result.push(jsonObj[key])}
console.log(result);