angular - 角度未正确映射字典对象
问题描述
我正在尝试将 json 字符串映射到 Angular 中的自定义对象。我认为我的问题在于将字典映射到 Angular 中的 Map。这是正在发送的对象的结构:
public class GeneratedConfiguration
{
public List<ServiceEnvironmentConfiguration> Configurations { get; set; } =
new List<ServiceEnvironmentConfiguration>();
public string Service { get; set; }
}
public class ServiceEnvironmentConfiguration
{
public string Environment { get; set; }
public SortedDictionary<string, SourcedPropertyValue> Properties { get; set; } =
new SortedDictionary<string, SourcedPropertyValue>();
}
public class SourcedPropertyValue
{
public string SourceConfiguration { get; set; }
public object Value { get; set; }
}
这是我在 Angular 中的模型的结构:
export interface Configurations {
Service: string;
Configurations: Configuration[];
}
export interface Configuration {
Environment: string;
Properties: Map<string, SourcedPropertyValue>;
}
export interface SourcedPropertyValue {
SourceConfiguration: string;
Value: any;
}
这就是我试图映射它的方式:
getConfigs(service: string): Observable<Configurations> {
return this.http.get<Configurations>(this.url).pipe(
catchError(this.handleError)
);
}
它通过环境变量正确映射,但属性始终列为未定义。所以我认为问题可能出在我的地图上?谁能告诉我如何更改我的模型以正确映射字典部分?
解决方案
推荐阅读
- javascript - 如何从 mongoose/mongoDB 模型中的数组中删除对象(基于它的 id)?
- mysql - 使用多个外键查询表
- python - 如何将 Python 添加到 PATH?
- c# - 类方法中的“this”是指被调用的还是默认的实例?
- xcode - dyld:未加载库:在 SPM 中添加 Nimble 后 @rpath/XCTest.framework/XCTest
- python - 有没有办法通过一个集合,同时添加项目并迭代它们?
- ssl - 如何最好地解决 SSL 加密对零拷贝优化的不利影响
- ruby-on-rails - 在 rails 应用程序中创建按钮不起作用。为什么不保存到数据库?
- apache - 使用自定义域名访问 docker 容器化应用程序
- mediastore - Android Q:从文件夹路径读取音频文件