给出以下JSON文件:
example.json
{
"labels": [
{
"AB": {
"title": "example title",
"desc": "example description"
}
},
{
"CD": {
"title": "another example title",
"desc": "another example description"
}
}
]
}
它可以在函数中使用:
const jsonData = require('./example.json');
export default function() {
const labels = jsonData.labels;
const entries = labels[0]['AB'].title; // Unresolved variable title
}
该代码在应用程序中有效。
但是,似乎IDE无法识别JSON文件中存在该标题键。
是否可以布局JSON文件结构,以便IDE知道需要什么键?