簡體   English   中英

使用 Axios 時如何解析 JSON 數組響應

[英]How to Parse JSON Array Response when using Axios

我想獲得https://animechan.vercel.app/api/available/anime上的所有字符串,但突然我無法獲得它,有人會幫助我嗎? 這是我的代碼:

axios.get('https://animechan.vercel.app/api/available/anime')
  .then(response => {
    console.log("Source of Anime Qoutes: \n\n\n" + JSON.parse(response.data));
  })
  .catch(error => {
    console.log(error);
});

Axios automagically deserializes the response body from JSON to a Javascript object, assuming the response's content type is application/json or you tell Axios to do so regardless. 請參閱文檔

https://axios-http.com/docs/intro

您只需要:

var axios = require("axios");

axios.get( 'https://animechan.vercel.app/api/available/anime' )
.then( response => {
  console.log(`Source of Anime Qoutes:`);
  console.log( response.data.join('\n') );
})
.catch(error => {
  console.log(error);
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM