javascript - Error in generating multidimensional array from JSON array -


i use javascript obtain data server through php.

php obtains data mysql, encodes json data , sends via http protocol client - in case, browser.

javascript i.e. shown below picks values , renders chart. testing i'm printing out conversion of jsonarray stringarray output of php.

any suggestions why when js code gets point below

mylogger("mylogger - newobject.dummmysetsjsonarr.entryid" + newobject.dummmysetsjsonarr.entryid); 

it throws following error seen in console:

   uncaught typeerror cannot read property 'entryid' of undefined 

here's example of db data converted json:

{"dummmysetsjsonarr":[{"entryid":"1","distance":"100","calories":"50"},{"entryid":"2","distance":"200","calories":"100"},{"entryid":"3","distance":"300","calories":"150"},{"entryid":"4","distance":"400","calories":"200"},{"entryid":"5","distance":"500","calories":"250"},{"entryid":"6","distance":"600","calories":"300"}],"success":1} 

and here's js:

    google.setonloadcallback(drawvisualization);      function drawvisualization() {        var req = false;       var jsonarry;        try {           // browsers           req = new xmlhttprequest();            mylogger("mylogger - xmlhttprequest() created");       } catch (e){           // ie           try{               req = new activexobject("msxml2.xmlhttp");                mylogger("mylogger - req = new activexobject(msxml2.xmlhttp);");                     } catch (e) {               // try older version               try{                   req = new activexobject("microsoft.xmlhttp");                    mylogger("mylogger - req = new activexobject(microsoft.xmlhttp);");                              } catch (e){                }           }       }    if (!req) {      mylogger("req === false");   } else {      mylogger("req === true");   }    // use onreadystatechange property   req.onreadystatechange = function() {         //mylogger("mylogger - req.onreadystatechange = function(){");        if(req.readystate == 4) {            mylogger("mylogger - req.readystate == 4");            if(req.status === 200) {              mylogger("mylogger - req.status === 200");              jsonarry = req.responsetext;              mylogger("mylogger - json array - " + jsonarry);              mylogger(" ------------- ");              var identedtext = json.stringify(jsonarry, null, 4);              var jsonstring = json.stringify(jsonarry);              mylogger("mylogger - unindented jsonstring - " + jsonstring);              var newobject = json.parse(jsonstring);              mylogger("mylogger - newobject " + newobject);              mylogger("mylogger - newobject.dummmysetsjsonarr.entryid" + newobject.dummmysetsjsonarr.entryid);  }  function mylogger(content) {     if (window.console && window.console.log) {         console.log("mylogger - " + content);     } } 

edit: i've reduced op code removing irrelevant bits.

any ideas appreciated

the error on line

mylogger("mylogger - newobject.dummmysetsjsonarr.entryid" + newobject.dummmysetsjsonarr.entryid); 

when try log newobject.dummmysetsjsonarr.entryid.

indeed, newobject.dummmysetsjsonarr.entryid undefined since newobject.dummmysetsjsonarr array.

for example, newobject.dummmysetsjsonarr[0].entryid valid.


Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

order - Notification for user in user account opencart -