繁体   English   中英

从json结果中提取数据标签

[英]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]

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

然后将其转换为html元素;

  • g = $(e)[0]; //索引0是div,如果您要查找特定元素,则可以将其替换

最后,您可以将其用作jQuery对象并提取数据值:

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

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

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

干杯!

e.dataundefined

您正在将e设置为user.entry.content.$t[0]

这意味着e$t的第一个字符,它看起来"\
长字符串,开头为: "\

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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