Timoney, Daniel (dt5972) | 324ee36 | 2017-02-15 10:37:53 -0500 | [diff] [blame] | 1 | try{ |
| 2 | var jsonStr='{}'; |
| 3 | jsonObj=JSON.parse(jsonStr); |
| 4 | var htmlObj ={}; |
| 5 | var objectId =0; |
| 6 | var level=0; |
| 7 | var htmlStr="" |
| 8 | htmlStr += "<html>"; |
| 9 | htmlStr += "<head>"; |
| 10 | htmlStr += "<script>"; |
| 11 | htmlStr += "function show(idVal){"; |
| 12 | htmlStr += " var val = \"<table border='1'>\" + document.getElementById(idVal).value + \"</table>\";"; |
| 13 | htmlStr += " document.getElementById('displayId').innerHTML = val;"; |
| 14 | htmlStr += "document.getElementById('displayId').style.display = \"block\";"; |
| 15 | //htmlStr += "alert(idVal);"; |
| 16 | //htmlStr += "alert(val);"; |
| 17 | htmlStr += "}"; |
| 18 | htmlStr += "</script>"; |
| 19 | htmlStr += "</head>"; |
| 20 | htmlStr += "<div id='displayId' style='display:none'></div>"; |
| 21 | htmlStr += "<div>\n<table border='1'>\n"; |
| 22 | printObjectValues(jsonObj,null,level); |
| 23 | htmlStr += "\n</table>\n</div>"; |
| 24 | //var pattern = new RegExp("\\n","g"); |
| 25 | //htmlstr =htmlStr.replace(pattern,''); |
| 26 | htmlStr += "</html>"; |
| 27 | //console.log(htmlStr); |
| 28 | |
| 29 | function tabs(level){ |
| 30 | return ''; |
| 31 | } |
| 32 | function tabsOrig(level){ |
| 33 | var tabs=""; |
| 34 | for(var i=0;i<level;i++){ |
| 35 | tabs += "\t"; |
| 36 | } |
| 37 | return tabs; |
| 38 | } |
| 39 | |
| 40 | function printObjectValues(jsonObj,pkey,level){ |
| 41 | var output=""; |
| 42 | var objectHtmlStr=""; |
| 43 | try{ |
| 44 | for (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 | } |
| 76 | return output; |
| 77 | } |
| 78 | |
| 79 | }catch(err){ |
| 80 | console.log( err ); |
| 81 | } |
| 82 | |
| 83 | function printArrayValues(arrObj,pkey,level){ |
| 84 | var output =""; |
| 85 | var arrayHtmlStr =""; |
| 86 | try{ |
| 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 | } |
| 103 | return output; |
| 104 | } |
| 105 | |
| 106 | function 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 | } |