Note that there are some explanatory texts on larger screens.

plurals
  1. POJavascript and Parsed JSON - Child node's ['@attributes'].type returns undefined
    primarykey
    data
    text
    <p>I've parsed a legitimate JSON object and I'm walking through the multidimensional array to first find the year based on a function argument and then the month within that year. </p> <p>My for loops are nested:</p> <pre><code> for (year in yearsData) { //If we've found the correct year... if (yearsData[year]['@attributes'].name == yearToGet) { //...walk through that year's child months for (month in yearsData[year]) { //This works! console.log(yearsData[year][month]); //This also works! console.log(yearsData[year][month]['@attributes']); //This does not work! ..but this is what I need! console.log(yearsData[year][month]['@attributes'].name); } } </code></pre> <hr> <p>I can track the object in Firebug's console (with valid output) all the way up to </p> <blockquote> <p>console.log(yearsData[year][month]['@attributes']);</p> </blockquote> <p>But the instant I add the type at the end (.name):</p> <blockquote> <p>yearsData[year][month]['@attributes'] is undefined.</p> </blockquote> <p>console.log(yearsData[year][month]); returns the valid object, and I can <em>see</em> the valid @attributes listed.</p> <p>I've checked the spelling multiple times; I've changed the name of the attribute to other things in case it was somehow conflicting with year's attributes..but I got nothin'. </p> <p>What simple thing am I missing?</p> <p>The JSON:</p> <pre><code>{ "year": [ { "@attributes": { "name": "2013" }, "month": { "@attributes": { "name": "January" }, "winner": "None!", "theme": "Nobody!" } } ] </code></pre> <p>}</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload