如何在打字稿中像数组一样解析Json对象。 MAP Firestore中的MAP

时间:2019-10-22 13:31:03

标签: angular google-cloud-firestore angularfire2 angular8

我想像数组一样解析driverDocumentDetails

JSON是从android(Java)HashMap数据结构实现的 MAP中的Angular Firestore 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);
    });
  }

1 个答案:

答案 0 :(得分:1)

您可以使用Object.keys来获取密钥,然后将其映射到新数组中:

var driverDocumentDetailsArray = Object.keys(this.driverDocument.driverDocumentDetails)
    .map(key => this.driverDocument.driverDocumentDetails[key]);

或者,如果可用,只需Object.values

var driverDocumentDetailsArray = Object.values(this.driverDocument.driverDocumentDetails);