2013-07-22 56 views
0

我想使用JQuery訪問以下JSON內容。內容:編碼:在JSON與JQuery

http://pipes.yahoo.com/pipes/pipe.run?_id=14756b1d828eae9693f6ef235de879cc&_render=json

我可以通過訪問標題和描述罰款:

var item_html = '<li><a href="'+item.link+'">'+item.title+'</a></li>'+item.description+''; 

,但我無法訪問內容:編碼:因爲語法錯誤,當我嘗試:

var item_html = '<li><a href="'+item.link+'">'+item.title+'</a></li>'+item.content:encoded+''; 

我敢肯定,有一個簡單的解決方案,但我無法得到我的東西。我已經嘗試了引號,因爲這對我來說最有意義,但一直無法讓它起作用。

在此先感謝。

+0

可能重複[如何訪問包含特殊字符的對象屬性?](http://stackoverflow.com/questions/12953704/how-to -access-object-properties-containing-special-characters) – Quentin

+0

難道不是'item ['content:encoded']'? – DevlshOne

+0

@DevlshOne - 是的,它會 – adeneo

回答

1

不能使用特殊標記像:直接,但你可以使用['PropertyName']

因此改變你的代碼是這樣的訪問數據;

var item_html = '<li><a href="'+item.link+'">'+item.title+'</a></li>'+item['content:encoded']+''; 

Here是演示,瞭解如何訪問您的數據

0

不能使用點符號有特殊字符,你將不得不使用該括號標記:

變化

item.content:encoded 

item['content:encoded'] 

還要注意,不能在LI之外的UL中具有文本節點:

'....</a></li>'+item.content:encoded+''; 

FIDDLE

+0

完美!現在工作得很好,謝謝。 – Chris