我正在使用 tumblr api 获取某个用户的数据,并且响应作为 js 而不是 json 提供:
https://taylorswift.tumblr.com/api/read?start=0&format=json&num=1
var tumblr_api_read = {"tumblelog":{"title":"Taylor Swift","description":"","name":"taylorswift","timezone":"US\/Eastern","cname":false,"feeds":[]},"posts-start":0,"posts-total":186,"posts-type":false,"posts":[{"id":"172426031730","url":"http:\/\/taylorswift.tumblr.com\/post\/172426031730","url-with-slug":"http:\/\/taylorswift.tumblr.com\/post\/172426031730\/did-you-see-what-hayley-kiyoko-said-about-taylor","type":"answer","date-gmt":"2018-03-30 22:27:43 GMT","date":"Fri, 30 Mar 2018 18:27:43","bookmarklet":0,"mobile":0,"feed-item":"","from-feed-id":0,"unix-timestamp":1522448863,"format":"html","reblog-key":"GJl0OUt4","slug":"did-you-see-what-hayley-kiyoko-said-about-taylor","is-submission":false,"like-button":"<div class=\"like_button\" data-post-id=\"172426031730\" data-blog-name=\"taylorswift\" id=\"like_button_172426031730\"><iframe id=\"like_iframe_172426031730\" src=\"https:\/\/assets.tumblr.com\/assets\/html\/like_iframe.html?_v=fc298e85f978b8662a643fe0a6b8c638#name=taylorswift&post_id=172426031730&color=black&rk=GJl0OUt4&root_id=172423870366\" scrolling=\"no\" width=\"20\" height=\"20\" frameborder=\"0\" class=\"like_toggle\" allowTransparency=\"true\" name=\"like_iframe_172426031730\"><\/iframe><\/div>","reblog-button":"<a href=\"https:\/\/www.tumblr.com\/reblog\/172426031730\/GJl0OUt4\" class=\"reblog_button\"style=\"display: block;width:20px;height:20px;\"><svg width=\"100%\" height=\"100%\" viewBox=\"0 0 21 21\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" xmlns:xlink=\"http:\/\/www.w3.org\/1999\/xlink\" fill=\"#000\"><path d=\"M5.01092527,5.99908429 L16.0088498,5.99908429 L16.136,9.508 L20.836,4.752 L16.136,0.083 L16.1360004,3.01110845 L2.09985349,3.01110845 C1.50585349,3.01110845 0.979248041,3.44726568 0.979248041,4.45007306 L0.979248041,10.9999998 L3.98376463,8.30993634 L3.98376463,6.89801007 C3.98376463,6.20867902 4.71892527,5.99908429 5.01092527,5.99908429 Z\"><\/path><path d=\"M17.1420002,13.2800293 C17.1420002,13.5720293 17.022957,14.0490723 16.730957,14.0490723 L4.92919922,14.0490723 L4.92919922,11 L0.5,15.806 L4.92919922,20.5103758 L5.00469971,16.9990234 L18.9700928,16.9990234 C19.5640928,16.9990234 19.9453125,16.4010001 19.9453125,15.8060001 L19.9453125,9.5324707 L17.142,12.203\"><\/path><\/svg><\/a>","note-count":"24565","reblogged-from-url":"http:\/\/shaking-off-the-bad-blood.tumblr.com\/post\/172423870366\/did-you-see-what-hayley-kiyoko-said-about-taylor","reblogged-from-name":"shaking-off-the-bad-blood","reblogged-from-title":"\"Samar, right?\"","reblogged_from_avatar_url_16":"https:\/\/78.media.tumblr.com\/avatar_ef3080f98ef4_16.png","reblogged_from_avatar_url_24":"https:\/\/78.media.tumblr.com\/avatar_ef3080f98ef4_24.png","reblogged_from_avatar_url_30":"https:\/\/78.media.tumblr.com\/avatar_ef3080f98ef4_30.png","reblogged_from_avatar_url_40":"https:\/\/78.media.tumblr.com\/avatar_ef3080f98ef4_40.png","reblogged_from_avatar_url_48":"https:\/\/78.media.tumblr.com\/avatar_ef3080f98ef4_48.png","reblogged_from_avatar_url_64":"https:\/\/78.media.tumblr.com\/avatar_ef3080f98ef4_64.png","reblogged_from_avatar_url_96":"https:\/\/78.media.tumblr.com\/avatar_ef3080f98ef4_96.png","reblogged_from_avatar_url_128":"https:\/\/78.media.tumblr.com\/avatar_ef3080f98ef4_128.png","reblogged_from_avatar_url_512":"https:\/\/78.media.tumblr.com\/avatar_ef3080f98ef4_512.png","reblogged-root-url":"http:\/\/shaking-off-the-bad-blood.tumblr.com\/post\/172423870366\/did-you-see-what-hayley-kiyoko-said-about-taylor","reblogged-root-name":"shaking-off-the-bad-blood","reblogged-root-title":"\"Samar, right?\"","reblogged_root_avatar_url_16":"https:\/\/78.media.tumblr.com\/avatar_ef3080f98ef4_16.png","reblogged_root_avatar_url_24":"https:\/\/78.media.tumblr.com\/avatar_ef3080f98ef4_24.png","reblogged_root_avatar_url_30":"https:\/\/78.media.tumblr.com\/avatar_ef3080f98ef4_30.png","reblogged_root_avatar_url_40":"https:\/\/78.media.tumblr.com\/avatar_ef3080f98ef4_40.png","reblogged_root_avatar_url_48":"https:\/\/78.media.tumblr.com\/avatar_ef3080f98ef4_48.png","reblogged_root_avatar_url_64":"https:\/\/78.media.tumblr.com\/avatar_ef3080f98ef4_64.png","reblogged_root_avatar_url_96":"https:\/\/78.media.tumblr.com\/avatar_ef3080f98ef4_96.png","reblogged_root_avatar_url_128":"https:\/\/78.media.tumblr.com\/avatar_ef3080f98ef4_128.png","reblogged_root_avatar_url_512":"https:\/\/78.media.tumblr.com\/avatar_ef3080f98ef4_512.png","tumblelog":{"title":"Taylor Swift","name":"taylorswift","cname":false,"url":"http:\/\/taylorswift.tumblr.com\/","timezone":"US\/Eastern","avatar_url_16":"https:\/\/78.media.tumblr.com\/avatar_c4f07fd82125_16.png","avatar_url_24":"https:\/\/78.media.tumblr.com\/avatar_c4f07fd82125_24.png","avatar_url_30":"https:\/\/78.media.tumblr.com\/avatar_c4f07fd82125_30.png","avatar_url_40":"https:\/\/78.media.tumblr.com\/avatar_c4f07fd82125_40.png","avatar_url_48":"https:\/\/78.media.tumblr.com\/avatar_c4f07fd82125_48.png","avatar_url_64":"https:\/\/78.media.tumblr.com\/avatar_c4f07fd82125_64.png","avatar_url_96":"https:\/\/78.media.tumblr.com\/avatar_c4f07fd82125_96.png","avatar_url_128":"https:\/\/78.media.tumblr.com\/avatar_c4f07fd82125_128.png","avatar_url_512":"https:\/\/78.media.tumblr.com\/avatar_c4f07fd82125_512.png"},"question":"Did you see what Hayley Kiyoko said about Taylor? I’m sad :(","answer":"<p>I did! I think people are actually misinterpreting the quote. I don\u2019t know if it is being taken out of context or what, but if you read the interview itself, I don\u2019t believe she was calling Taylor unoriginal or boy crazy. She was just defending her choice for wanting to make videos with female love interests. <\/p>\n\n<p>It is actually very similar to when Taylor back in 2014\/2015 would say in interviews how she believes people are sexist when they call her out for writing about her exes but don\u2019t call out people like Ed Sheeran or Bruno Mars for writing about theirs. She wasn\u2019t calling out Ed or Bruno at the time, yet rather criticizing how the media and the public handle the situation. Hayley appears to be doing the same.<\/p>"}]};
然后我想获取tumblr_api_read
的数据,虽然我可以使用eval
来执行脚本并获取返回值,但是我担心eval
不安全。
所以我想知道是否有其他方法来获取数据?
我尝试过 js-unescape
或 html-unescape
数据,但都不起作用。
最佳答案
来自documentation ,我只能找到一个参数debug
。如果传递值 1
,它将返回 JSON,而不用 var
前缀:
https://taylorswift.tumblr.com/api/read/json?start=0&num=1&debug=1
如果这还不行,那么不幸的是,我们已经没有太多的余地了。您应该尽快切换到最新的 API。
关于javascript - 解析js中没有 `eval`的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49772396/