[英]extract data-tag from a json result
这是我的API请求的结果:
// API callback
showAuth({
"version": "1.0",
"encoding": "UTF-8",
"entry": {
"content": {
"type": "html",
"$t": "\u003Cdiv id=\"data\" class=\"democlass\" data-author=\"Mr. Jhon Doe\" data-cat=\"Technology\" data-url=\"http:\/\/www.qbtemplates.com\/\"\u003E\u003C\/div\u003E \u003Cimg alt=\"Treasury : Minimal Responsive News \u0026 Magazine Blogger Template\" src=\"https:\/\/4.bp.blogspot.com\/-Kv_-Jg5krkA\/V8PFfwe1ikI\/AAAAAAAAAU0\/4J4Dlc0lOJIW2Qbe45TDTMVo4_Ij8MQhACLcB\/s1600\/Treasury---http___treasury-soratemplates.blogspot.co.jpg\" title=\"Treasury : Minimal Responsive News \u0026 Magazine Blogger Template\" \/\u003E\u003Cbr \/\u003E \u003C!-- \u003Cul class=\"item-cta\"\u003E \u003Cli class=\"demo\"\u003E \u003Ca data-demo=\"true\" href=\"http:\/\/treasury-soratemplates.blogspot.com\/\" rel=\"nofollow\" target=\"_blank\"\u003EPreview\u003C\/a\u003E \u003C\/li\u003E \u003Cli class=\"download\"\u003E \u003Ca data-download=\"true\" href=\"http:\/\/qbtemplates.16mb.com\/files\/Treasury%20Free%20Version.zip\" rel=\"nofollow\" target=\"_blank\"\u003EDownload\u003C\/a\u003E \u003C\/li\u003E\u003C\/ul\u003E--\u003E \u003Cbr \/\u003E\u003Cdiv style=\"text-align: justify;\"\u003ETreasury is all purpose Blogging blogger theme which can be used for all your blogs like travel, food, life, programming, everyday, fashion and everything you want to blog about. On top of this, great and friendly support makes your website setup experience completely smooth! Treasury Magazine design is excellent for a news, newspaper, magazine, article and editorial publishing or review and rating site. It uses the best clean SEO practices, and on top of that, it’s fast, simple, and easy to use. \u003C\/div\u003E"
},
"author": [{
"name": {
"$t": "Mikey"
},
"uri": {
"$t": "http:\/\/www.blogger.com\/profile\/05775556662956xxxxxx"
},
"email": {
"$t": "noreply@blogger.com"
},
"gd$image": {
"rel": "http://schemas.google.com/g/2005#thumbnail",
"width": "16",
"height": "16",
"src": "http:\/\/img1.blogblog.com\/img\/b16-rounded.gif"
}
}],
}
});
首先,将[0]
然后将其转换为html元素;
最后,您可以将其用作jQuery对象并提取数据值:
h = $(g).data('作者')
i = $(g).data('cat')
干杯!
e.data
是undefined
。
您正在将e
设置为user.entry.content.$t[0]
这意味着e
是$t
的第一个字符,它看起来"\
长字符串,开头为: "\
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.