2
我会读取应该是格式正确的用户输入对象。如何抛出异常,如果一个对象结构不匹配/拟合另一个
也就是说,输入对象现在可以具有未在界面中定义的任何键或子结构。
如果用户给出无效对象,我该如何抛出异常?
预先定义的接口
export interface InputStructureInterface {
"tableName": string,
"viewType": string,
"structureName": string,
"sections": Array<Section>,
}
interface Section{
"name": string,
"fields": Array<Field>
}
interface Field{
"fieldName": string,
"relationType": string,
"relationName": null,
"fieldUi": FieldUi
}
interface FieldUi {
"fieldType": string,
"label": strin
}
有效输入结构
这种结构下的定义InputStructureInterface
一个子集
{
"tableName": "User",
"viewType": "List View",
"structureName": "personal_data_settings_list_view",
"sections": [
{
"name": null,
"fields": [
{
"fieldName": "Name",
"relationType": null,
"relationName": null,
"fieldUi": {
"fieldType": "string",
"label": "Name"
},
}
]
}
]
}
无效的输入结构
因为viewTypeTHIS_IS_A_TYPO
,nameTHIS_IS_A_TYPO
是ñ不存在于接口上
{
"tableName": "User",
"viewTypeTHIS_IS_A_TYPO": "List View",
"structureName": "personal_data_settings_list_view",
"sections": [
{
"nameTHIS_IS_A_TYPO": null,
"fields": [
{
"fieldNameTHIS_IS_A_TYPO": "Name"
}
]
}
]
}
非常感谢您的信息支持。我会检查它〜 – newBike
看一看,我更新了答案,我认为这段代码对你有用。您只需进行所需的更改即可将其放入代码中。 – Diullei