繁体   English   中英

我试图从 JSON 文件中记录作者姓名和引用,但代码不起作用?

[英]I am trying to log the author name and the quote from the JSON file, but the code is not working?

我正在尝试将数据数组对象中的 quoteAuthor 和 quoteText 登录到控制台,但它不起作用有人可以帮助我,为什么此代码不起作用?

const showJokes = () => {

  return fetch("https://quote-garden.herokuapp.com/api/v3/quotes")
    .then(response => response.json())
    .then(data => {
      data.data.forEach(message => {
        let author = message.quoteAuthor;
        let quote = message.quoteText;
        return showAllJokes(`${author} - ${quote}`)
      })
    });

}

function showAllJokes(fullName) {
  console.log(fullName);
}

json文件

我只能在您提供的代码段中看到functions声明,也许您确实忘记调用showJokes函数?

 const showJokes = () => { return fetch("https://quote-garden.herokuapp.com/api/v3/quotes") .then(response => response.json()) .then(data => { data.data.forEach(message => { let author = message.quoteAuthor; let quote = message.quoteText; return showAllJokes(`${author} - ${quote}`) }) }); } function showAllJokes(fullName) { console.log(fullName); } showJokes() // <- Add this line

暂无
暂无

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

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