javascript - Show enter contents of JSON -


question ::

i know redundant question, finding little in other similar questions...

i have json file.

i can load json fine, when try output specific element this

div.innerhtml = jsonfromfile[element]; 

i this...

[object object] 

as output...

how entire element display instead of [object object]?

more code feel how being done up...

var activity; function jsfr() {     $.getjson('myjson.json', function(response){     jsonfromfile = response;     })   } 

.

.

.

solution :: francis stalin's answer

i added new function...

        var items;     function outty(data) {              $.each(data, function(key, val) {                 items=items+key+","+val+";";             });     } 

and set depth on json leaving me object send outty...

    dpth = jsonfromfile["elementone"]["elsubone"]["elsubonesub"];     outty(dpth);     div.innerhtml=items; 

here's html shows div prints to...

    <div class="col-rght">         <div class="text" id="postcomp"></div>     </div> <!--div class="col-rght"--> 

this turns object of desired json depth ugly string can format display..

if html lists check out how stalin did it, weary of appendto('div')... place list in every div. try putting name of class of div want print period leading it, appendto('.outputbox')

you can't append json object directly ur html. u have parse , convert string

$.getjson('myjson.json', function(data) { var items = []; $.each(data, function(key, val) { items.push('<li id="' + key + '">' + val + '</li>'); }); $('<ul/>', { 'class': 'my-new-list', html: items.join('') }).appendto('div'); }); 

http://api.jquery.com/jquery.getjson/


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -