json - 将嵌套的 json 分配给变量
问题描述
我有以下界面:
export interface IdataTypes {
dataType: {
Categories: string[],
isSelected: boolean,
}
}
和以下 JSON
{
"Sensitive Personal Data": {
"isSelected": "false",
"legalReference": "",
"Categories": [
"Health Data",
"Genetic Data",
"Biometric Data",
"Trade Union Data",
"Religious Data",
"Political Opinion",
"Philosophical Belief",
"Racial or Ethic Origin",
"Sex Life",
"Sexual Orientation"
]
},
"Personal Data with Higher Risk":{
"isSelected":"false",
"legalReference":"",
"Categories":["location","Financial/Social Status","Data Related to Profiling",
"video surveillance","data on adoption and custody"]
}
}
我想读取文件的“dataTypeCategories”并将其分配给接口文件的变量。所以我做以下
for(let i=0; i<response["Personal Data with Higher Risk"].Categories.length;i++){
this.dataTypeHighRisk["Personal Data with Higher Risk"][i].Categories.push
(response["Personal Data with Higher Risk"].Categories[i]);
this.dataTypeHighRisk["Personal Data with Higher Risk"][i].isSelected=false;
;
}
我收到此错误:core.js:1542 ERROR 错误:未捕获(承诺中):ReferenceError:未定义类别
你能告诉我怎么做吗?我是 javascript 和 angular 的新手。
更新数组定义为:dataTypeHighRisk: IdataTypes[]=[]; 我不知道如何定义属性“具有高风险的个人数据/
解决方案
推荐阅读
- amazon-web-services - 使用来自另一个区域的 AWS Private Api Gateway
- import - 如何从 TIFF 文件中的文本包围的具体行中获取数字(如果在记事本中查看)并将其用于 Digital Micrograph 的脚本中?
- python - 在 Packet Tracer 中模拟温度传感器值,无需真实硬件
- python - ValueError:发现样本数量不一致的输入变量:[676, 540]
- web - Squarespace 产品列表页面编辑
- python - 如何在不删除重复项的情况下找到最常用的单词?
- firebase - 颤振 - 类型'列表
' 不是类型 'String' 的子类型 - html - 如何将这些按钮放置在其容器的底部?
- javascript - 在javascript字符串中表示@符号
- docker - Docker 卷挂载为空