我正在尝试在我的 React 应用程序中读取 Json 文件,但控制台显示我的 json 文件的 url 是 404。任何人都可以检查一下我的代码中有什么问题吗
以下是浏览器控制台中显示的错误。当我打开网络选项卡中显示的 json url 时,它会重定向到该页面而不是显示 json -
下面是我的代码 -
-
import React from 'react';
import Header from './Header';
import Container from './Container'
import Footer from './Footer'
class App extends React.Component{
constructor(props) {
super(props);
this.state = {
error: null,
isLoaded: false,
products: []
};
}
componentDidMount() {
fetch("../json/results.json",{
headers : {
'Content-Type': 'application/json',
'Accept': 'application/json'
}
})
.then(res => res.json())
.then(
console.log("--------"),
(result) => {
this.setState({
isLoaded: true,
products: result.Products
});
}, …Run Code Online (Sandbox Code Playgroud)