簡體   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