gpt4 book ai didi

javascript - 从 json 结果中提取数据标签

转载 作者:行者123 更新时间:2023-12-03 04:50:01 24 4
gpt4 key购买 nike

这是我的 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"
}
}],
}
});

我只是想将一些数据提取到变量中

function showAuth(user) {
var b = user.entry.author[0];
c = b.name.$t;
d = b.gd$image.src.replace(/\/s[0-9]+(-*c*)\//, '/s60$1/');
e = user.entry.content.$t[0];
f = e.data - author;
document.write('<img class="auvtar" alt="' + c + '" src="' + d + '" title="' + c + '"/>' + f + '')
}

变量 cd 结果正确的数据,但变量 f 结果没有数据(我的意思是整个代码不是如果我启用变量f,则可以正常工作。

我想从 entry.content 中提取 data-catdata-authordata-url code> 分成单独的变量,例如 fgh

最佳答案

首先,去掉

中的[0]
  • e = user.entry.content.$t[0];

然后将其转换为html元素;

    g = $(e)[0];//索引 0 是 div,你可以替换它,如果你想要查找特定元素

最后你可以将它用作 jQuery 对象并提取数据值:

  • h = $(g).data('作者')

  • i = $(g).data('cat')

  • j = $(g).data('url')

干杯!

关于javascript - 从 json 结果中提取数据标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42698644/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com