I'm trying to parse an itunes RSS feed by converting it to JSON via php and then inserting it with jQuery .ajax.
First is the php
<?php
$url = "http://schoolceoshow.libsyn.com/rss";
$fileContents = file_get_contents($url);
$fileContents = str_replace(array("\n", "\r", "\t"), '', $fileContents);
$fileContents = trim(str_replace('"', "'", $fileContents));
$simpleXml = simplexml_load_string($fileContents);
$json = json_encode($simpleXml);
echo $json;
?>
Now the javascript
var root = location.origin + "/";
$.ajax({
url:root + "php/podcast.php",
type:"GET",
data:"json",
success:function(data){
var dataObject = $.parseJSON(data);
console.log(dataObject.channel.item[0].enclosure);
},
error:function(){
console.log("failed");
}
});
What that logs out is
Object {@attributes: Object}
@attributes: Object
length: "25583209"
type: "audio/mpeg"
url: "http://traffic.libsyn.com/schoolceoshow/SchoolCEOShow-007.mp3"
My only issue here is accessing the @attributes key. How do I access a key with an @ symbol? Thanks!