Created
February 1, 2013 07:45
-
-
Save biswarupadhikari/4689978 to your computer and use it in GitHub Desktop.
Generate Table from JSON Object
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function createTableFromJSON(jsonObj){ | |
var table=''; | |
var tableHeader=jsonObj[0]; | |
table+='<table>'; | |
table+='<thead><tr>'; | |
for(index in tableHeader){ | |
table+='<th>'+index+'</th>'; | |
} | |
table+='</tr></thead>'; | |
table+='<tbody>'; | |
for(i=0;i<jsonObj.length;i++){ | |
table+='<tr>'; | |
var obj=jsonObj[i]; | |
for(index in obj){ | |
value = obj[index]; | |
table+='<td>'+value+'</td>'; | |
} | |
table+='</tr>'; | |
} | |
table+='</tbody>'; | |
table+='</table>'; | |
return table; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment