简体   繁体   中英

content:encoded: in JSON with JQuery

I'm trying to access the following JSON content using JQuery.

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

I can access the title and description fine by using:

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

but I'm having trouble accessing content:encoded: because of a syntax error when I try:

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

I'm sure there's a simple solution but I can't get my had around it. I've tried putting quotes in as that makes the most sense to me but haven't been able to get it to work.

Thanks in advance.

you can't use special token like : directly but you can access your data using ['PropertyName']

so change your code to be like this;

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

Here is demo to see how to access your data

You can't use dot notation with special characters, you'll have to use bracket notation for that:

change

item.content:encoded

to

item['content:encoded']

Also note that you can't have textnodes in an UL outside the LI's:

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

FIDDLE

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM