Convert xml to json and format [duplicate]




This question already has an answer here:




I am using the CTA API (http://ift.tt/1sNdvQI) and the responses are xml. I'd like to convert to json after my fetch in a backbone collection. The response looks like this:



<?xml version="1.0"?>
<bustime-response>
<route>
<rt>1</rt>
<rtnm>Bronzeville/Union Station</rtnm>
<rtclr>#336633</rtclr>
</route>
<route>
<rt>2</rt>
<rtnm>Hyde Park Express</rtnm>
<rtclr>#993366</rtclr>
</route>
</bustime-response>


I'd like it to look like this:



[
{
"rt": "1",
"rtnm": "Bronzeville/Union Station",
"rtclr": "#336633"
},
{
"rt": "2",
"rtnm": "Hyde Park Express",
"rtclr": "#993366"
}
]


What's the best way to do this?


No comments:

Post a Comment