JSON Object(오브젝트) 데이터를 표(Table) 형식으로 보여주게 하는 함수(자체제작)
function json_to_string(json)
{
var html = "";
if(typeof json === 'object')
{
html += "<table class='json-table'>\n";
for(var key in json)
{
var row = json[key];
var sub_html = "";
if(typeof row === 'object')
{
sub_html = json_to_string(row);
}
else
{
if(key.toLowerCase().indexOf("timestamp") != -1)
{
sub_html = moment(row).format("YYYY-MM-DD HH:mm:ss");
}
else
{
sub_html = row;
}
}
var key_width = "";
if(isNaN(key) == false)
{
key_width = "20";
}
else
{
key_width = "120";
}
html += "\t<tr>\n";
html += " \t<th style='width:"+key_width+"px; text-align:left;' class='ellip'>"+key+"</th>\n";
html += " \t<td>"+sub_html+"</td>\n";
html += "\t</tr>\n";
}
html += "</table>\n";
}
else
{
html += json;
}
return html;
}