blob: 20c9cfeb6428fbcceb8999621174a07b1bc1f32a [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";
22console.log("<html><table border='1'>");
23printObjectValues(jsonObj,null,level);
24console.log("</table></html>");
25htmlStr += "\n</table>\n</div>";
26//var pattern = new RegExp("\\n","g");
27//htmlstr =htmlStr.replace(pattern,'');
28htmlStr += "</html>";
29//console.log(htmlStr);
30
31//console.dir(htmlObj);
32var keyObj={};
33for (var key in htmlObj) {
34 var idx = key.lastIndexOf(".");
35 if(idx != -1){
36 var str = key.substr(0,idx);
37 keyObj[str] ='';
38 }else{
39 keyObj[key] ='';
40 }
41 //console.log(str);
42}
43
44console.dir(keyObj);
45console.log("<ul>");
46for (var key in keyObj) {
47 console.log("<li>" + key + "</li>");
48}
49console.log("</ul>");
50
51function tabs(level){
52return '';
53}
54function tabsOrig(level){
55 var tabs="";
56 for(var i=0;i<level;i++){
57 tabs += "\t";
58 }
59 return tabs;
60}
61
62function printObjectValues(jsonObj,pkey,level){
63var output="";
64var objectHtmlStr="";
65try{
66for (var key in jsonObj) {
67 if (jsonObj.hasOwnProperty(key)) {
68 var v = jsonObj[key];
69 if(typeof v === 'object' && Array.isArray(v) === false){
70 var nkey="";
71 if(pkey != null){
72 nkey = pkey + "." + key;
73 }else{
74 nkey = key;
75 }
76 var str=printObjectValues(v,nkey,level+2);
77 }else if(typeof v === 'object' && Array.isArray(v) === true){
78 var nkey="";
79 if(pkey != null){
80 nkey = pkey + "." + key;
81 }else{
82 nkey = key;
83 }
84 var str = printArrayValues(v,nkey,level+2);
85 }else{
86 if(pkey != null){
87 //console.log(pkey + "." + key + ":" +printValue(v) );
88 console.log("<tr><td>" + pkey + "." + key + "</td><td>" +printValue(v) + "</td></tr>" );
89 htmlObj[pkey + "." + key ] = printValue(v);
90 }else{
91 //console.log( key + ":" +printValue(v) );
92 console.log("<tr><td>" + key + "</td><td>" +printValue(v) + "</td></tr>" );
93 htmlObj[key ] = printValue(v);
94 }
95 //printValue(v);
96 }
97 }
98}
99}catch(err){
100 console.log(err);
101}
102return output;
103}
104
105}catch(err){
106console.log( err );
107}
108
109function printArrayValues(arrObj,pkey,level){
110var output ="";
111var arrayHtmlStr ="";
112try{
113 for(var i=0;arrObj != null && i<arrObj.length;i++){
114 var o=arrObj[i];
115 if(typeof o === 'object' && Array.isArray(o) === false){
116 var nkey = pkey +"[" + i + "]" ;
117 var str = printObjectValues(o,nkey,level+2);
118 }else if(typeof o === 'object' && Array.isArray(v) === true){
119 var nkey = pkey +"[" + i + "]" ;
120 var str = printArrayValues(o,nkey,level);
121 }else{
122 console.log("<tr><td>" + pkey + "." + key + "</td><td>" +printValue(o) + "</td></tr>" );
123 htmlObj[pkey + "." + key ] = printValue(o);
124 //console.log(pkey + ":" +printValue(o) );
125 //output += tabs(level) + "<tr><td>" + printValue(o) + "</td></tr>\n";
126 }
127 }
128}catch(err){
129 console.log(err);
130}
131return output;
132}
133
134function printValue(obj){
135 if(obj != undefined){
136 if(typeof obj == 'string'){
137 return "'" + obj + "'";
138 }else{
139 return obj;
140 }
141 }else{
142 return "";
143 }
144}