我目前有一个json响应,如下所示:
FixedIp: {_IpAddress: "10.98.0.199", _Subnet: "255.255.254.0", _DefaultGateway: "10.98.0.1", _MTU: "1500", _HostName: "icmp-5b2607a"}
IsDhcpEnabled: {_Value: "false"}
StaticRoute: {_IsEnabled: "true", _TargetIpAddress: "10.98.0.0", _Subnet: "255.255.254.0", _Gateway: "255.255.254.1"}
我创建了一个打字稿界面,如下所示:
export interface MediaAdapter {
IsDhcpEnabled: IsDhcpEnabled;
FixedIp: FixedIP;
StaticRoute: StaticRoute;
}
export interface FixedIP {
_DefaultGateway: string;
_MTU: string;
_Subnet: string;
_IpAddress: string;
}
export interface IsDhcpEnabled {
_Value: boolean;
}
export interface StaticRoute {
_IsEnabled: boolean;
_Subnet: string;
_Gateway: string;
_TargetIpAddress: string;
}
我的回应如下:
const parsedJSON = JSON.parse(JSON.stringify(obj[key]));
const value: MediaAdapter = <MediaAdapter>parsedJSON as MediaAdapter;
我不知何故把所有的布尔值都当作字符串。我的布尔值arent被解析为字符串。 我做错了什么?