简体   繁体   English

如何使用此API并将其转换为JS对象

[英]How can I take this API and turn it into a JS object

I am trying to take this api: https://newsapi.org/v1/articles?source=techcrunch&sortBy=top&apiKey=9a9c9037fecf4bcb9e49ffa581f8713b and assign it to a variable in JS where if i console.log(variable) inside of a console of a browser it will give me a tree pertaining to the api. 我正在尝试使用此api: https : //newsapi.org/v1/articles? source = techcrunch & sortBy = top & apiKey =9a9c9037fecf4bcb9e49ffa581f8713b并将其分配给JS中的变量,如果我在控制台的控制台内使用console.log(variable)浏览器会给我一棵与api有关的树。 This is probably a horrible explanation, so here's a picture of what i'm looking to get: https://imgur.com/a/nhJU5 这可能是一个可怕的解释,所以这是我想要得到的图片: https : //imgur.com/a/nhJU5

Barren Code: https://imgur.com/a/Nq7gS src=' https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js ' in HTML I used this Yahoo YQL in previous RSS apps I've made but clearly it doesn't work the same on this one 贫瘠的代码: https//imgur.com/a/Nq7gS src =' https ://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js'在HTML中,我使用了Yahoo YQL在我以前制作的RSS应用中,但显然在此应用上它不起作用

var variable;
function reqListener () {
  variable=oReq.response;
  console.log(variable);
}

var oReq = new XMLHttpRequest();
oReq.addEventListener("load", reqListener);
oReq.responseType="json";
oReq.open("GET", "https://newsapi.org/v1/articles?source=techcrunch&sortBy=top&apiKey=9a9c9037fecf4bcb9e49ffa581f8713b");
oReq.send();

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

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