0
我想通過PHP將它轉換爲JSON解析一個iTunes RSS源,然後用jQuery .ajax插入它。無法訪問對象鍵「@屬性」的iTunes RSS訂閱
首先是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;
?>
現在的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");
}
});
這也就註銷是
Object {@attributes: Object}
@attributes: Object
length: "25583209"
type: "audio/mpeg"
url: "http://traffic.libsyn.com/schoolceoshow/SchoolCEOShow-007.mp3"
我在這裏的唯一的問題是訪問@屬性鍵。如何使用@符號訪問密鑰?謝謝!
你嘗試'dataObject時[ '@屬性']':我已經添加到我的代碼是什麼
回答在被發現? – adeneo
即將到來我說我找到了答案,就是這樣。找到答案在http://stackoverflow.com/questions/6932745/parsing-json-w-symbol-in-it – thatgibbyguy