Javascript 无法访问对象密钥“@属性“;用于itunes RSS源

Javascript 无法访问对象密钥“@属性“;用于itunes RSS源,javascript,php,json,parsing,rss,Javascript,Php,Json,Parsing,Rss,我试图通过php将itunes RSS提要转换为JSON,然后用jQuery.ajax插入,从而解析itunes RSS提要 首先是php <?php $url = "http://schoolceoshow.libsyn.com/rss"; $fileContents = file_get_contents($url); $fileContents = str_replace(array("\n", "\r", "\t"), '', $fileContent

我试图通过php将itunes RSS提要转换为JSON,然后用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;
?>
注销的是什么

Object {@attributes: Object}
  @attributes: Object
    length: "25583209"
    type: "audio/mpeg"
    url: "http://traffic.libsyn.com/schoolceoshow/SchoolCEOShow-007.mp3"

我唯一的问题是访问@attributes键。如何访问带有@符号的密钥?谢谢

解决方案是使用括号符号访问对象。我在代码中添加的是

var enclosure = dataObject.channel.item[0].enclosure;
console.log(enclosure["@attributes"]);

答案在:

您是否尝试了
dataObject['@attributes']
?我想说我找到了答案,就这样。找到了答案
var enclosure = dataObject.channel.item[0].enclosure;
console.log(enclosure["@attributes"]);