Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.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响应对象的特定数据类型存储在数组中(例如:数字),以作为变量传入数据源_Json_Angular_Typescript - Fatal编程技术网

如何将json响应对象的特定数据类型存储在数组中(例如:数字),以作为变量传入数据源

如何将json响应对象的特定数据类型存储在数组中(例如:数字),以作为变量传入数据源,json,angular,typescript,Json,Angular,Typescript,在应用程序中的某个位置声明类型,例如在服务中: export class AppComponent implements OnInit { title: String = "Heatmap"; constructor(private app:AppServiceService) { } ngOnInit(): void { this.app.getdata().subscribe ( (re

在应用程序中的某个位置声明类型,例如在服务中:

export class AppComponent implements OnInit {
    title: String = "Heatmap";
  
    constructor(private app:AppServiceService) { }
    ngOnInit(): void {
        this.app.getdata().subscribe
        (
            (response)=>{console.log(response)}       
        )
    }
   

    dataSource: Object []= [
    [1, this.num.value, 9, 23, 0, 39, 0],
    [0, 18, 37, 0, 0, 50, 0]
    
    ];
    
 
    
   
}
如果响应具有简单类型,则可以直接使用它:

ngOnInit() {
    this.appService.getData().subscribe((response: GetDataResponse) => {
      console.log(response);
    })
  }

你能提供更多的细节吗。
ngOnInit() {
    this.appService.getData().subscribe((response: GetDataResponse) => {
      console.log(response);
    })
  }
ngOnInit() {
    this.appService.getData().subscribe((response: {data: number[]}) => {
      console.log(response);
    })
}