Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Json 角度8 Typescript展平嵌套数组_Json_Angular_Typescript_Angular8 - Fatal编程技术网

Json 角度8 Typescript展平嵌套数组

Json 角度8 Typescript展平嵌套数组,json,angular,typescript,angular8,Json,Angular,Typescript,Angular8,我有嵌套的JSON数据,需要将其展平,以便在一个表中向用户显示所有选项,而不显示下拉列表 数据看起来像这样 0: ID: 4 Date: "2019-08-09T00:00:00" Data: Year: 2019 Identification: "F31073" nestedArray: Array(1) 0: array1ID: "31" array1Code: "073" nestedArray2: Array(4) 0:

我有嵌套的JSON数据,需要将其展平,以便在一个表中向用户显示所有选项,而不显示下拉列表

数据看起来像这样

0:
ID: 4
Date: "2019-08-09T00:00:00"
Data:
Year: 2019
Identification: "F31073"
nestedArray: Array(1)
   0:
      array1ID: "31"
      array1Code: "073"
      nestedArray2: Array(4)
      0:
        array2info: 24
        nestedArray3: Array(8)
          0:
          array3Identifier: "ECF5EE44-50E1-4F07-AB38-CF7A60A6276F"
          array3Number: 31
          arrayThreeIndicator: "N"
          nestedArray4: Array(1)
             0:
             array4Info: "31"
             array4Code: "073"
我看过很多解决方案,但没有一个能为我提供一个平面的数据数组

这里更新的是我试图展平的JSON数据,以便对每个嵌套数组复制之前的字段,并且在没有嵌套数组的情况下,所有数据都是可见的

"[{"FileCustomerIdentifier":4,"TransmissionDate":"2019-08- 
 09T00:00:00","TransmissionData":"{\r\n  \"cropYear\": 2019,\r\n  
 \"originatorIdentification\": \"F31073\",\r\n  \"farm\": [\r\n    {\r\n      
 \"administrativeStateFsaCode\": \"31\",\r\n      
 \"administrativeCountyFsaCode\": \"073\",\r\n      \"farmNumber\": 
  4609,\r\n      
 \"tract\": [\r\n        {\r\n          \"tractNumber\": 24,\r\n          
 \"field\": [\r\n            {\r\n              \"cluIdentifier\": 
 \"ECF5EE44-50E1-4F07-AB38-CF7A60A6276F\",\r\n              
 \"fieldNumber\": 
 31,\r\n              \"cluProducerReviewRequestIndicator\": \"N\",\r\n              
 \"agriculturalProductionPlan\": [\r\n                {\r\n                  
 \"stateAnsiCode\": \"31\",\r\n                  \"countyAnsiCode\": 
 \"073\",\r\n                  \"coreProductCode\": \"0102\",\r\n                  
 \"coreProductTypeCode\": \"0794\",\r\n                  
 \"productIntendedUseCode\": \"0007\",\r\n                  
 \"originalReportedAcreage\": 109.93,\r\n                  
 \"finalReportedAcreage\": 109.93,\r\n                  
 \"reportedAcreageModifiedIndicator\": \"N\",\r\n                  
 \"plantedDateModifiedIndicator\": \"N\",\r\n                  
 \"productPlantingCode\": null,\r\n                  
 \"irrigationPracticeCode\": \"N\",\r\n                  
 \"organicPracticeTypeCode\": \"N\",\r\n                  
 \"croppingPracticeCode\": 997,\r\n                  \"producerShare\": 
 [\r\n                    
 {\r\n                      \"fileCustomerIdentifier\": 2,\r\n                      
 \"producerSharePercent\": 1\r\n                    }\r\n                  
 ]\r\n                }\r\n              ]\r\n            },\r\n            
 {\r\n              \"cluIdentifier\": \"5E83C2F1-6399-46DD-8695- 
 90CEAAF02721\",\r\n              \"fieldNumber\": 32,\r\n              
 \"cluProducerReviewRequestIndicator\": \"N\",\r\n              
 \"agriculturalProductionPlan\": [\r\n                {\r\n                  
 \"stateAnsiCode\": \"31\",\r\n                  \"countyAnsiCode\": 
 \"073\",\r\n                  \"coreProductCode\": \"0041\",\r\n                  
 \"coreProductTypeCode\": \"0964\",\r\n                  
 \"productIntendedUseCode\": \"0016\",\r\n                  
 \"originalReportedAcreage\": 43.73,\r\n                  
 \"finalReportedAcreage\": 43.73,\r\n                  
 \"reportedAcreageModifiedIndicator\": \"N\",\r\n                  
 \"originalPlantedDate\": \"2019-05-02\",\r\n                  
 \"finalPlantedDate\": \"2019-05-02\",\r\n                  
 \"plantedDateModifiedIndicator\": \"N\",\r\n                  
 \"productPlantingCode\": null,\r\n                  
 \"irrigationPracticeCode\": \"N\",\r\n                  
 \"organicPracticeTypeCode\": \"N\",\r\n                  
 \"croppingPracticeCode\": 997,\r\n                  \"producerShare\": 
 [\r\n                    
 {\r\n                      \"fileCustomerIdentifier\": 4,\r\n                      
 \"producerSharePercent\": 0.5\r\n                    },\r\n                    
 {\r\n                      \"fileCustomerIdentifier\": 5,\r\n                      
 \"producerSharePercent\": 0.5\r\n                    }\r\n                  
 ]\r\n                }\r\n              ]\r\n            },\r\n            
 {\r\n              \"cluIdentifier\": \"0E021A77-6BA2-4FAA-A522- 
 A1F383C0FBF5\",\r\n              \"fieldNumber\": 29,\r\n              
 \"cluProducerReviewRequestIndicator\": \"N\",\r\n              
 \"agriculturalProductionPlan\": [\r\n                {\r\n                  
 \"stateAnsiCode\": \"31\",\r\n                  \"countyAnsiCode\": 
 \"073\",\r\n                  \"coreProductCode\": \"0102\",\r\n                  
 \"coreProductTypeCode\": \"0794\",\r\n                  
 \"productIntendedUseCode\": \"0007\",\r\n                  
 \"originalReportedAcreage\": 11.77,\r\n                  
 \"finalReportedAcreage\": 11.77,\r\n                  
 \"reportedAcreageModifiedIndicator\": \"N\",\r\n                  
 \"plantedDateModifiedIndicator\": \"N\",\r\n                  
 \"productPlantingCode\": null,\r\n                  
 \"irrigationPracticeCode\": \"N\",\r\n                  
 \"organicPracticeTypeCode\": \"N\",\r\n                  
 \"croppingPracticeCode\": 997,\r\n                  \"producerShare\": 
 [\r\n                    
 {\r\n                      \"fileCustomerIdentifier\": 2,\r\n                      
 \"producerSharePercent\": 1\r\n                    }\r\n                  
 ]\r\n                }\r\n              ]\r\n            },\r\n            
 {\r\n              \"cluIdentifier\": \"BFE94518-7B5E-40A3-BF71- 
 0EA6B932C3F9\",\r\n              \"fieldNumber\": 28,\r\n              
 \"cluProducerReviewRequestIndicator\": \"N\",\r\n              
 \"agriculturalProductionPlan\": [\r\n                {\r\n                  
 \"stateAnsiCode\": \"31\",\r\n                  \"countyAnsiCode\": 
 \"073\",\r\n                  \"subfieldNumber\": \"A\",\r\n                  
 \"coreProductCode\": \"0102\",\r\n                  
 \"coreProductTypeCode\": 
 \"0794\",\r\n                  \"productIntendedUseCode\": \"0007\",\r\n                  
 \"originalReportedAcreage\": 52.0,\r\n                  
 \"finalReportedAcreage\": 52.0,\r\n                  
 \"reportedAcreageModifiedIndicator\": \"N\",\r\n                  
 \"plantedDateModifiedIndicator\": \"N\",\r\n                  
 \"productPlantingCode\": null,\r\n                  
 \"irrigationPracticeCode\": \"N\",\r\n                  
 \"organicPracticeTypeCode\": \"N\",\r\n                  
 \"croppingPracticeCode\": 997,\r\n                  \"producerShare\": 
  [\r\n                    
 {\r\n                      \"fileCustomerIdentifier\": 2,\r\n                      
 \"producerSharePercent\": 1\r\n                    }\r\n                  
 ]\r\n                }\r\n              ]\r\n            },\r\n            
 {\r\n              \"cluIdentifier\": \"9ac10b70-0d9d-4a38-97f7- 
 22e63a3c0f9d\",\r\n              \"fieldNumber\": 2,\r\n              
 \"cluProducerReviewRequestIndicator\": \"N\",\r\n              
 \"agriculturalProductionPlan\": [\r\n                {\r\n                  
 \"stateAnsiCode\": \"31\",\r\n                  \"countyAnsiCode\": 
 \"073\",\r\n                  \"subfieldNumber\": \"A\",\r\n                  
 \"coreProductCode\": \"0102\",\r\n                  
 \"coreProductTypeCode\": 
 \"0794\",\r\n                  \"productIntendedUseCode\": \"0013\",\r\n                  
 \"originalReportedAcreage\": 0.22,\r\n                  
 \"finalReportedAcreage\": 0.22,\r\n                  
 \"reportedAcreageModifiedIndicator\": \"N\",\r\n                  
 \"plantedDateModifiedIndicator\": \"N\",\r\n                  
 \"productPlantingCode\": null,\r\n                  
 \"irrigationPracticeCode\": \"N\",\r\n                  
 \"organicPracticeTypeCode\": \"N\",\r\n                  
 \"croppingPracticeCode\": 997,\r\n                  \"producerShare\": 
 [\r\n                    
 {\r\n                      \"fileCustomerIdentifier\": 2,\r\n                      
 \"producerSharePercent\": 1\r\n                    }\r\n                  
 ]\r\n                },\r\n                {\r\n                  
 \"stateAnsiCode\": \"31\",\r\n                  \"countyAnsiCode\": 
 \"073\",\r\n                  \"subfieldNumber\": \"B\",\r\n                  
 \"coreProductCode\": \"0041\",\r\n                  
 \"coreProductTypeCode\": 
 \"0964\",\r\n                  \"productIntendedUseCode\": \"0016\",\r\n                  
 \"originalReportedAcreage\": 18.58,\r\n                  
 \"finalReportedAcreage\": 18.58,\r\n                  
 \"reportedAcreageModifiedIndicator\": \"N\",\r\n                  
 \"originalPlantedDate\": \"2019-05-02\",\r\n                  
 \"finalPlantedDate\": \"2019-05-02\",\r\n                  
 \"plantedDateModifiedIndicator\": \"N\",\r\n                  
 \"productPlantingCode\": null,\r\n                  
 \"irrigationPracticeCode\": \"N\",\r\n                  
 \"organicPracticeTypeCode\": \"N\",\r\n                  
 \"croppingPracticeCode\": 997,\r\n                  \"producerShare\": 
 [\r\n                    
 {\r\n                      \"fileCustomerIdentifier\": 5,\r\n                      
 \"producerSharePercent\": 0.5\r\n                    },\r\n                    
 {\r\n                      \"fileCustomerIdentifier\": 4,\r\n                      
 \"producerSharePercent\": 0.5\r\n                    }\r\n                  
 ]\r\n                }\r\n              ]\r\n            },\r\n            
 {\r\n              \"cluIdentifier\": \"940ebc4b-fdc9-4cae-b9af- 
 b0b360afba5f\",\r\n              \"fieldNumber\": 4,\r\n              
 \"cluProducerReviewRequestIndicator\": \"N\",\r\n              
 \"agriculturalProductionPlan\": [\r\n                {\r\n                  
 \"stateAnsiCode\": \"31\",\r\n                  \"countyAnsiCode\": 
 \"073\",\r\n                  \"subfieldNumber\": \"A\",\r\n                  
 \"coreProductCode\": \"0041\",\r\n                  
 \"coreProductTypeCode\": 
 \"0964\",\r\n                  \"productIntendedUseCode\": \"0016\",\r\n                  
 \"originalReportedAcreage\": 10.64,\r\n                  
 \"finalReportedAcreage\": 10.64,\r\n                  
 \"reportedAcreageModifiedIndicator\": \"N\",\r\n                  
 \"originalPlantedDate\": \"2019-05-02\",\r\n                  
 \"finalPlantedDate\": \"2019-05-02\",\r\n                  
 \"plantedDateModifiedIndicator\": \"N\",\r\n                  
 \"productPlantingCode\": null,\r\n                  
 \"irrigationPracticeCode\": \"N\",\r\n                  
 \"organicPracticeTypeCode\": \"N\",\r\n                  
 \"croppingPracticeCode\": 997,\r\n                  \"producerShare\": [\r\n                    
 {\r\n                      \"fileCustomerIdentifier\": 4,\r\n                      
 \"producerSharePercent\": 0.5\r\n                    },\r\n                    
 {\r\n                      \"fileCustomerIdentifier\": 5,\r\n                      
 \"producerSharePercent\": 0.5\r\n                    }\r\n    …"

非常感谢您的帮助

如果嵌套数组键相同,则可以递归执行:

type NestedData={nested:NestedData[]}[]
函数展平(嵌套数据:嵌套数据){
设展平=[];
对于(嵌套数据的常量{nested,…restData}){
flatted.push(restData);
如果(!nested | |!nested.length)继续;
展平=展平.concat(展平(嵌套))
}
返回平直;
}  
常数展平=展平(数据);

你明白了。

谢谢你的回答……这就是使用你的解决方案返回的结果{ID:4,日期:“2019-08-09T00:00:00”,数据:{…}你可以看到最后一个元素是一个尚未展平的数组。你能包含一个实际数据的JSON表示吗?仍然是一个很大的丑陋的…可能是这种格式吗?`````{“a”:{“b”:{“c”:{}}```