我正在尝试获取一个 JSON 文件,但它返回错误Uncaught (in promise) SyntaxError: Unexpected token < in JSON at position 0 and 304: Not Modified。我尝试添加标题'Content-Type': 'application/json,'Accept': 'application/json'但随后返回错误404:未找到。
这是我获取 JSON 的代码:
import React from 'react';
export default class LabExperiment extends React.Component {
componentWillMount() {
const readmePath = require("./docs/iat/iatDependency.json");
fetch("./docs/iat/iatDependency.json")
.then(response => {
response.json();
})
.then(text => {
console.log(text);
});
}
render() {
return(
<div>Hello</div>
)
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的 json 文件:
{
"js": [
"../jsPsych/jspsych.js",
"../jsPsych/plugins/jspsych-iat-image.js",
"../jsPsych/plugins/jspsych-iat-html.js",
"../jsPsych/plugins/jspsych-html-keyboard-response.js"
],
"css": [ …Run Code Online (Sandbox Code Playgroud)