【发布时间】:2023-01-07 02:39:02
【问题描述】:
我的 src 文件夹中有一个包含本地 JSON 文件的 React 项目。我正在使用 fetch 并在获取文件时遇到问题。
[
{
"id": 1,
"field1": "some data",
"field2": 63,
"field3": ["info", "info", "info"],
"array1":[14, 35, 22, 22, 7],
"array2": [8, 21, 14, 13, 5],
"Link": "https://trailhead.salesforce.com"
}
]
async function loadJSON (url) {
const res = await fetch(url);
return await JSON.parse(JSON.stringify(res));
}
loadJSON('../file.json')
.then(data => {
console.log(data);
});
This is what I get in the console.
When my return statement is return await (res) I get this
任何帮助将不胜感激。
【问题讨论】: