Codesandbox.io 发回 html 数据而不是 Json 数据

问题描述

我目前正在处理 codeandBox 上的代码问题,我正在尝试使用 http get 请求从提供的链接中检索 json 数据。但是,当我 console.log 响应时,我只接收 html 数据,这是我在发出 http 请求时从未见过的。有没有其他人在显示 JSON 数据时遇到过这个问题并有使用代码和框的提示

谢谢!

import React,{ useState } from "react";
import "../styles.css";
import axios from "axios";

export default function App() {
  axios
    .get(`www.sbir.gov/api/solicitations.json?keyword=sbir`)
    .then((response) => {
      console.log(response);
    })
    .catch((error) => {
      console.log(error);
    });

  return (
    <div className="App">
      <h1>Hello CodeSandBox</h1>
      <h2>Start editing to see some magic happen!</h2>
    </div>
  );
}

解决方法

而不是console.log(response) 尝试 console.log(response.json())