javascript - 从本地文件读取 JSON 但地图功能出错
问题描述
我关注了几篇关于如何在 React 中从本地文件读取 json 数据的文章,他们推荐使用 map 函数。喜欢https://morioh.com/p/316b1492cfda
我收到一个错误
Property 'map' does not exist on type '{ updated: number; }'.ts(223)
这是我的代码
import UpdatedFile from '../public/updated.json';
const[Updated,setUpdated]= useState("9/9/2020");
const newdata = UpdatedFile.map((data) =>{ // This is where the error is coming
return (
setUpdated({map.updated})
)
});
这就是我的 JSON 文件的样子。
{
"updated": 1599692605913
}
知道为什么它不将地图识别为有效功能吗?
解决方案
推荐阅读
- javascript - 如何将 JSON 配置文件保存到用户的谷歌驱动器并再次检索它?
- android - android库项目中的DI
- django - 来自 Angular8 的发布数据包含空的 QueryDict 但 Django 中 request.body 中的数据
- django - 根据 django ORM 中的喜欢和评论将帖子划分为动态类别
- c++ - 如何使用地图对文本进行编码?
- json - 如何使用 SQL 确定父对象中 JSON 对象的数量
- windows - Autohotkey (ahk) GUI 十字准线实现
- c# - 在 MVC 中设置数据绑定 Dropdownlist 的默认值
- flutter - connectedResult 在颤振应用程序的启动中返回null?
- rpa - UIPath - 没有 Orchestrator 的计划