angular - 如何像 typescript 中的数组一样解析 Json 对象。MAP Firestore 内的 MAP
问题描述
我想像driverDocumentDetails
数组一样解析。
JSON是从android(Java)HashMap数据结构Angular Firestore MAP内部MAP实现的
{
"driverDocumentDetails":{
"fhgfh":{
"documentCategoryID":"fhgfh",
"documentCategoryName":"Pan Card",
"documentUploadedDateTime":null,
"reasonForRejection":null,
"uploaded":false,
"uploadedDocumentURL":null,
"verified":false
},
"bjhbh":{
"documentCategoryID":"bjhbh",
"documentCategoryName":"Driving License",
"documentUploadedDateTime":null,
"reasonForRejection":null,
"uploaded":false,
"uploadedDocumentURL":null,
"verified":false
},
"hgvjh":{
"documentCategoryID":"hgvjh",
"documentCategoryName":"NOC",
"documentUploadedDateTime":null,
"reasonForRejection":null,
"uploaded":false,
"uploadedDocumentURL":null,
"verified":false
}
},
"driverID":"bhbjhbjhbj",
"hgchg":[
{
"bjnk":"jhbjhb",
"fhfyhgf":"jjb"
},
{
"gfhg":"jgjuy",
"gh":"guguj"
}
]
}
onCustom(recordRow) {
console.log("onCustom Driver docs data---->",recordRow);
this.crudService.ReadDriverDocuments(recordRow.data.id).subscribe(data => {
this.driverDocument = data.data();
console.log('ReadDriverDocuments',this.driverDocument);
});
}
解决方案
您可以使用Object.keys
获取键,然后将其映射到新数组中:
var driverDocumentDetailsArray = Object.keys(this.driverDocument.driverDocumentDetails)
.map(key => this.driverDocument.driverDocumentDetails[key]);
或者,如果它可用,只需Object.values
var driverDocumentDetailsArray = Object.values(this.driverDocument.driverDocumentDetails);
推荐阅读
- python - 我可以让人们在他们安装的具有不同 CUDA 依赖项的版本之上使用不同的 Tensorflow-gpu 版本吗?
- css - 将 Bulma/Sass 与 Django 集成
- r - 删除文本中数字符比大于平均值的所有句子
- python - 图像去模糊
- c# - Xamarin Android WebView 访问 sessionStorage 返回 null
- django - 如何从 django-filters.FilterList 获取请求参数
- spring - 使用 orderBy 的 Spring JPA 命名查询不起作用
- docker - 没有 docker pull 的 Docker 保存
- node.js - Heroku 通过 POST 请求、multer 或 nodemailer H=18 反复崩溃
- ruby - Ruby:使用数组列表来选择特定的列