title: jquery loop through json
body: <p>Hi I am trying to loop through a json file like so:</p>
  
  <pre><code>$.each(data.playlists.playlist, function(i, item) {
  
                $("#contentC").append('&lt;p&gt;' + item.id + '&lt;/p&gt;'); 
                $("#contentC").append('&lt;p&gt;' + item.title + '&lt;/p&gt;'); 
                $("#contentC").append('&lt;p&gt;' + item.url + '&lt;/p&gt;'); }
             ); 
  </code></pre>
  
  <p><strong>json:</strong></p>
  
  <pre><code>{
     "playlists":{
        "playlist":[
           {
              "id":"8391802",
              "title":"Second Playlist",
              "description":"",
              "date":"2011-03-06T18:53:33",
              "size":"10",
              "duration":"2267",
              "streamable":"0",
              "creator":"http:\/\/www.last.fm\/user\/jon21021985",
              "url":"http:\/\/www.last.fm\/user\/jon21021985\/library\/playlists\/4zv5m_second_playlist",
              "image":[
                 {
                    "#text":"",
                    "size":"small"
                 },
                 {
                    "#text":"",
                    "size":"medium"
                 },
                 {
                    "#text":"",
                    "size":"large"
                 },
                 {
                    "#text":"",
                    "size":"extralarge"
                 }
              ]
           },
           {
              "id":"8372409",
              "title":"All-american Rejects",
              "description":"",
              "date":"2011-02-28T13:30:01",
              "size":"6",
              "duration":"785",
              "streamable":"0",
              "creator":"http:\/\/www.last.fm\/user\/jon21021985",
              "url":"http:\/\/www.last.fm\/user\/jon21021985\/library\/playlists\/4zg6x_all-american_rejects",
              "image":[
                 {
                    "#text":"",
                    "size":"small"
                 },
                 {
                    "#text":"",
                    "size":"medium"
                 },
                 {
                    "#text":"",
                    "size":"large"
                 },
                 {
                    "#text":"",
                    "size":"extralarge"
                 }
              ]
           }
        ],
        "@attr":{
           "user":"jon21021985"
        }
     }
  }
  </code></pre>
  
  <p>the problem is the data changes if there is only one playlist then I get 'undefined'</p>
  
  <pre><code>   {
     "playlists":{
        "playlist":{
           "id":"1319510",
           "title":"Untitled",
           "description":"",
           "date":"2007-10-18T12:17:58",
           "size":"1",
           "duration":"345",
           "streamable":"0",
           "creator":"http:\/\/www.last.fm\/user\/john",
           "url":"http:\/\/www.last.fm\/user\/john\/library\/playlists\/sa52_",
           "image":[
              {
                 "#text":"",
                 "size":"small"
              },
              {
                 "#text":"",
                 "size":"medium"
              },
              {
                 "#text":"",
                 "size":"large"
              },
              {
                 "#text":"",
                 "size":"extralarge"
              }
           ]
        },
        "@attr":{
           "user":"john"
        }
     }
  }
  </code></pre>