Json 我认为我的问题是API提供了一个对象而不是一个数组。所以我需要将对象修改为数组?

Json 我认为我的问题是API提供了一个对象而不是一个数组。所以我需要将对象修改为数组?,json,typescript,api,object,angular9,Json,Typescript,Api,Object,Angular9,我遇到了这个错误:找不到类型为“object”的不同支持对象“[object object]”。NgFor只支持绑定到数组之类的可重用文件 我试图从API获取数据,但它向我显示了这个错误,因为我还在学习,请指导我如何处理这种错误 元数据-service.service.ts 我对数据阵列感兴趣 Pincode.ts register-page.component.ts register-page.component.html {{pin.pincode}} {{modifiedText}}

我遇到了这个错误:找不到类型为“object”的不同支持对象“[object object]”。NgFor只支持绑定到数组之类的可重用文件

我试图从API获取数据,但它向我显示了这个错误,因为我还在学习,请指导我如何处理这种错误

  • 元数据-service.service.ts
  • 我对数据阵列感兴趣

  • Pincode.ts
  • register-page.component.ts
  • register-page.component.html
  • 
    {{pin.pincode}}
    {{modifiedText}}

    错误:找不到类型为“object”的不同支持对象“[object]”。NgFor只支持绑定到数组之类的可重用文件


    它显示了这个错误。

    需要迭代的数组在api响应对象中,因此在

    this._metadataService.GetPincodes()
       .subscribe(data => {
          this.observeData = data;
        });
    

    通过
    this.observeData=data.data
    更改
    this.observeData=data.data

    需要迭代的数组位于api响应对象内,因此在

    this._metadataService.GetPincodes()
       .subscribe(data => {
          this.observeData = data;
        });
    
    通过
    this.observeData=data.data

    
    export class Pincodes {
        pincode : number
        village : string
        taluka : string
        district : string
        state : string
    }
    
    import { Component, OnInit } from '@angular/core';
    import { data } from 'jquery';
    import { Pincodes } from 'src/app/Model/Pincodes';
    import { MetadataServiceService } from 'src/app/shared/services/metadata-service.service';
    import { Albums } from "src/app/Model/albums";
    import { Observable, of } from 'rxjs';
    import {MatTableDataSource, MatTableModule} from '@angular/material/table';
    import { report } from 'process';
    
    
    @Component({
      selector: 'app-register-page',
      templateUrl: './register-page.component.html',
      styleUrls: ['./register-page.component.css']
    })
    
    export class RegisterPageComponent implements OnInit {
    
    
     observeData : Pincodes[]  
      modifiedText: any;
      PinSelected : any = {}
    
     
     
    
    
      constructor(private _metadataService: MetadataServiceService) {  }
    
      ngOnInit(){
        
       this._metadataService.GetPincodes()
       .subscribe(data => {
          this.observeData = data;
        });
      }
    onPincodeSelected(val : Pincodes){
        console.log("value" + val);
        this.customFunction(val)
      }
      customFunction(val : Pincodes){
        this.modifiedText = "The Selected Pin was " + val.pincode + " and selected District is " + val.village
          console.log("modifiedText" + this.modifiedText);
          console.log("Pincode Selected" + this.PinSelected);
          console.log("observeData Selected" + this.observeData);
          
          
      }
      
    }
    
    
    <select
            [(ngModel)]="PinSelected"
            (ngModelChange)="onPincodeSelected($event)"
          >
            <option *ngFor="let pin of observeData" [ngValue]="pin">
              {{ pin.pincode }}
            </option>
          </select>
          <div>
            <p>{{ modifiedText }}</p>
          </div>
    
    this._metadataService.GetPincodes()
       .subscribe(data => {
          this.observeData = data;
        });