鑑於這種對象:獲取對象的屬性值,其中的關鍵是一個空字符串
: http://www.w3.org/2005/Atom
gd: http://schemas.google.com/g/2005
openSearch: http://a9.com/-/spec/opensearch/1.1/
app: http://www.w3.org/2007/app;
media: http://search.yahoo.com/mrss/
我如何獲得第一屬性的值?我懷疑這是一個簡單的過程,但我畫了一個空白。提前致謝。
的目標是建成這樣的:
服務器端(PHP):
$namespaces = $feedXML->getNamespaces(true);
$arr = array(
'Status' => 'Success',
'Message' => 'Feed fetched.',
'Namespaces' => $namespaces,
'Feed XML' => $feedXML
);
echo json_encode($arr);
客戶端(JS):
var output = '';
for (property in dataj["Namespaces"]) {
output += property + ': ' + dataj["Namespaces"][property] + '; ';
}
alert(output);
我想能夠檢查命名空間來查看這是Atom還是RDF。
這聽起來像只是迭代每個屬性將是最好的方式。
這段代碼實際上工作嗎?因爲我所得到的是[Uncaught SyntaxError:Unexpected token':'](http://jsfiddle.net/davidThomas/4kNhP/)。 –
什麼是確切的代碼?你的對象是如何構建的? –
這不是有效的JavaScript對象。我確信api會發送正確編碼的JSON對象(例如'{「xmlns」:「http://www.w3.org/2005/Atom」,「xmlns $ gd」:「http://schemas.google的.com /克/ 2005" }')。 –