blob: f8830f38bc0126f4b14c1beaf8dc2e20ece865a9 [file] [log] [blame]
Timoney, Daniel (dt5972)324ee362017-02-15 10:37:53 -05001try{
2var jsonStr='{}';
3jsonObj=JSON.parse(jsonStr);
4var htmlObj ={};
5var objectId =0;
6var level=0;
7var htmlStr=""
8htmlStr += "<html>";
9htmlStr += "<head>";
10htmlStr += "<script>";
11htmlStr += "function show(idVal){";
12htmlStr += " var val = \"<table border='1'>\" + document.getElementById(idVal).value + \"</table>\";";
13htmlStr += " document.getElementById('displayId').innerHTML = val;";
14htmlStr += "document.getElementById('displayId').style.display = \"block\";";
15//htmlStr += "alert(idVal);";
16//htmlStr += "alert(val);";
17htmlStr += "}";
18htmlStr += "</script>";
19htmlStr += "</head>";
20htmlStr += "<div id='displayId' style='display:none'></div>";
21htmlStr += "<div>\n<table border='1'>\n";
22printObjectValues(jsonObj,null,level);
23htmlStr += "\n</table>\n</div>";
24//var pattern = new RegExp("\\n","g");
25//htmlstr =htmlStr.replace(pattern,'');
26htmlStr += "</html>";
27//console.log(htmlStr);
28
29function tabs(level){
30return '';
31}
32function tabsOrig(level){
33 var tabs="";
34 for(var i=0;i<level;i++){
35 tabs += "\t";
36 }
37 return tabs;
38}
39
40function printObjectValues(jsonObj,pkey,level){
41var output="";
42var objectHtmlStr="";
43try{
44for (var key in jsonObj) {
45 if (jsonObj.hasOwnProperty(key)) {
46 var v = jsonObj[key];
47 if(typeof v === 'object' && Array.isArray(v) === false){
48 var nkey="";
49 if(pkey != null){
50 nkey = pkey + "." + key;
51 }else{
52 nkey = key;
53 }
54 var str=printObjectValues(v,nkey,level+2);
55 }else if(typeof v === 'object' && Array.isArray(v) === true){
56 var nkey="";
57 if(pkey != null){
58 nkey = pkey + "." + key;
59 }else{
60 nkey = key;
61 }
62 var str = printArrayValues(v,nkey,level+2);
63 }else{
64 if(pkey != null){
65 console.log(pkey + "." + key + ":" +printValue(v) );
66 }else{
67 console.log(key + ":" +printValue(v) );
68 }
69 //printValue(v);
70 }
71 }
72}
73}catch(err){
74 console.log(err);
75}
76return output;
77}
78
79}catch(err){
80console.log( err );
81}
82
83function printArrayValues(arrObj,pkey,level){
84var output ="";
85var arrayHtmlStr ="";
86try{
87 for(var i=0;arrObj != null && i<arrObj.length;i++){
88 var o=arrObj[i];
89 if(typeof o === 'object' && Array.isArray(o) === false){
90 var nkey = pkey +"[" + i + "]" ;
91 var str = printObjectValues(o,nkey,level+2);
92 }else if(typeof o === 'object' && Array.isArray(v) === true){
93 var nkey = pkey +"[" + i + "]" ;
94 var str = printArrayValues(o,nkey,level);
95 }else{
96 console.log(pkey + ":" +printValue(o) );
97 //output += tabs(level) + "<tr><td>" + printValue(o) + "</td></tr>\n";
98 }
99 }
100}catch(err){
101 console.log(err);
102}
103return output;
104}
105
106function printValue(obj){
107 if(obj != undefined){
108 if(typeof obj == 'string'){
109 return "'" + obj + "'";
110 }else{
111 return obj;
112 }
113 }else{
114 return "";
115 }
116}