Turning this XML into JSON Jquery -


so have xml winamp

<dict>         <key>track id</key><integer>0</integer>         <key>name</key><string>american idol 2013</string>         <key>artist</key><string>amber holcomb</string>         <key>album artist</key><string>amber holcomb</string>         <key>album</key><string>unknown album</string>         <key>kind</key><string>mpeg audio file</string>         <key>size</key><integer>3645</integer>         <key>total time</key><integer>233000</integer>         <key>date modified</key><date>thu mar 14 12:11:12 2013</date>         <key>date added</key><date>thu apr 04 16:10:15 2013</date>         <key>bitrate</key><integer>128</integer>         <key>location</key><string>file://localhost/z:%5canthony%5cmusic%5citunes%5citunes%20media%5cmusic%5cunknown%20artist%5cunknown%20album%5camber%20holcomb%20-%20a%20moment%20like%20this%20-%20studio%20version%20-%20american%20idol%202013.mp3</string>         <key>file folder count</key><integer>-1</integer>         <key>library folder count</key><integer>-1</integer>       </dict> 

i want turn jsonarray

var myarray = {"trackid":0, "name":"american idol 2013"...};

i found out how loop through each tag, i'm can't seem wrap head how this. thinking of creating predefined json array or {"trackid": "", "name":""}, , when json complete, push master json (so sorry if i'm not explaining correctly).

is there way make single array of keys , rest, , merge them json array? use advice please.

thank help.

i answered own question think...

var key1 = "keyname"; var val1 = "value";  var myarray = {};  myarray[key1] = val1; 

so here's xml: http://honciano.com/kayokee/ci/uploads/xmlbackup2.xml

this code used create json array. don't know if proper way of doing it, got work. problem having getting value "key" tag , value after "key" tag, tags not "key" either "string" or "integer".

so created....

$.ajax({                 url: "<? echo base_url().'uploads/songlist.xml';?>",                 datatype: 'html',                  success: function(data){                     var myarray ={"track":[]};                     var key1 = "";                     var val1 = "";                               var arraycontainer = {};                     var mycount = 0;                     $(data).find("dict").children("dict").children("dict").each(function(){                            $(this).children().each(function(i, e){                             var nodekey=(this).nodename;                              if(nodekey=="key"){                                 key1 = $(this).text();                              } else {                                 val1 = $(this).text();                                 arraycontainer[key1] = val1;                                 mycount++;                                 //console.log("key1:"+key1+" - val1:"+val1+" - mycount:"+mycount);                             }                                             if(mycount==14){                                 myarray.track.push(arraycontainer);                                 arraycontainer={};                                 mycount=0;                                 //console.log("cutoff new line");                             }                                    });                       });                      $.each(myarray.track, function(i, obj){                         $.each(obj, function(e, val){                             console.log("e:"+e+" - val:"+val);                         });                     });                   }             }) 

it totally works , giving me want. all!


Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

php - HTTP_REFERER woes: How can I allow access to a specific page, only when a visitor has visited another specific page beforehand? -

java Extracting Zip file -