title: javascript skipping first level of recursive thingy
body: <p>I'm reading in a JSON object into a normal looking js object. There is a class called Style that can contain styles (in an array) and has a name and a value. A few different objects can contain styles (also as arrays)</p>
  
  <p>Now I created a stand-alone function that returns an array of styles as follows:</p>
  
  <pre><code>function getStylesFromJson(jsonObj)
  {
  this.complete = false;
  var ret = new Array();
  
  for (var style in jsonObj)
      {
          temp = new Style();
          temp.loadFromJson(jsonObj[style]);
          ret.push(temp);
          document.write("xxxxxxx&lt;br/&gt;");
          document.write(jsonObj[style].sName);
          document.write(jsonObj[style].sValue);
          document.write("&lt;br/&gt;");
          document.write(temp.name);
          document.write(temp.value);
          document.write("&lt;br/&gt;yyyyy");
          document.write("&lt;br/&gt;");
  
          while (!temp.loadFromJson.complete)
          {
              var a = 1; //waste some time
          }
      }
  
  this.complete = true;
  return ret;
  }
  </code></pre>
  
  <p>And in the Style class I made the function:</p>
  
  <pre><code>this.loadFromJson = function(jsonObj)
  {
      this.loadFromJson.complete  = false;
      this.name                   = jsonObj.sName;
      this.value                  = jsonObj.sValue;   
      this.styles = getStylesFromJson(jsonObj.aStyles);   
      this.loadFromJson.complete  = true;
  }
  </code></pre>
  
  <p>Here's a snippit of the JSON that gets executed to make the object that's passed to getStylesFromJson:</p>
  
  <pre><code>{
      "aStyles": {
          "font": {
              "sValue": "",
              "sName": "font",
              "aStyles": {
                  "size": {
                      "sValue": "2000000",
                      "sName": "size",
                      "aStyles": []
                  }
              }
          },
          "fill": {
              "sValue": "",
              "sName": "fill",
              "aStyles": {
                  "bill": {
                      "sValue": "blue",
                      "sName": "bill",
                      "aStyles": []
                  },
                  "mill": {
                      "sValue": "blue",
                      "sName": "mill",
                      "aStyles": []
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p>and here's the output of the document.write's in getStylesFromJson:</p>
  
  <pre><code>font
  colorpurple
  yyyyy
  xxxxxxx
  colorred
  colorred
  yyyyy
  xxxxxxx
  fill
  colorred
  yyyyy
  xxxxxxx
  size12
  size12
  yyyyy
  </code></pre>
  
  <p>what I want is to construct a complete object hierarchy from the json but it seems to be leaving out the top level of the structure. I'm not getting any js errors it's just that stuff like "font" and "fill" are left out and I cant tell why.</p>
  
  <p>Any Ideas?</p>
  
  <p>Here's a bit more info for the commenters:
  I did use JSON.parse, but as far as I know there's no way to parse something in such a way as to make sure it ends up as a custom object of a class specified elsewhere. I need to take a string of JSON than contains a recursive data structure and turn it into an object hierarchy that has certain functionality. Is there any way to do this?</p>
  
  <p>here's a bit of an explanation of what the words and the x and y stuff means:
  a jsonised object called jsonObj is passed into a function that then uses jsonObj to create a Style. "xxxxx" marks the beginning of the output of a single iteration. Next name and value of the JSON-style is output (no spaces). The value can be empty. Next the name and value of the Style that was constructed from the JSON style info is output. It should be the same but it isn't.</p>
  
  <pre><code>xxxx
  colorpurple
  colorpurple
  yyyy
  </code></pre>
  
  <p>would imply correct construction of a Style of name "color" and value purple while</p>
  
  <pre><code>xxxx
  fill
  colorred
  yyyy
  </code></pre>
  
  <p>creeps me out</p>