[英]TypeError: Cannot read properties of undefined (reading 'forEach') How to overcome this problem?
Create a script which uses the "forEach" method.创建一个使用“forEach”方法的脚本。 png Json is an array of objects with the following sequence: png Json 是一个对象数组,其顺序如下:
"uri": ".....",
"id": "0222 2.PNG",
"type": "IMG"
},
gets error: pngJson.png.forEach((element) => { TypeError: Cannot read properties of undefined (reading 'forEach')得到错误:pngJson.png.forEach((element) => { TypeError: Cannot read properties of undefined (reading 'forEach')
The debugger reads the file correctly until it fails调试器正确读取文件,直到失败
Here is a code snippet:这是一个代码片段:
let pngMap = new Map();
let pngJson = JSON.parse(fs.readFileSync(staticJson));
pngJson.png.forEach((element) => {
pngMap.set(element.id, element.uri);
});
if your Json is如果你的 Json 是
{ "data": [ { "uri": "QmNvzUyXezTMorSXTrFnAyBUJrH6K41GsWqeS", "id": "f.PNG", "type": "10" } ] }
shouldn't it be pngJson.data.forEach
instead of pngJson.png.forEach
?...不应该是pngJson.data.forEach
而不是pngJson.png.forEach
吗?...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.