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的循环结构,UI运行时错误TypeError_Json_Angular_Typescript - Fatal编程技术网

JSON的循环结构,UI运行时错误TypeError

JSON的循环结构,UI运行时错误TypeError,json,angular,typescript,Json,Angular,Typescript,我在尝试解析和字符串化一些JSON数据时出错 在这一行: this.copyOfColumns = JSON.parse(JSON.stringify(Object.assign([], this.columns))); 以下是整个@输入(使用角度4): @Input() 设置gridColumns(GridColumnSAR:Array){ log('gridcolumnsar'); console.log(gridcolumnsar); this.columns=this.sortActi

我在尝试解析和字符串化一些JSON数据时出错

在这一行:

this.copyOfColumns = JSON.parse(JSON.stringify(Object.assign([], this.columns)));
以下是整个@输入(使用角度4):

@Input()
设置gridColumns(GridColumnSAR:Array){
log('gridcolumnsar');
console.log(gridcolumnsar);
this.columns=this.sortActiveAndInactiveColumns(gridcolumnsar);
console.log('this.columns');
console.log(this.columns);
this.copyOfColumns=JSON.parse(JSON.stringify(Object.assign([],this.columns));
console.log('this.copyOfColumns');
console.log(this.copyOfColumns);
}
以下是记录到控制台(this.columns)的数据以及以下错误:


我假设您希望通过使用
JSON.parse(JSON.stringify())
对数组进行深度复制。显然,您的数据结构中有一个错误,它使
JSON.stringify()
失败


您应该清理数据,使其不包含ciruclar引用,或者可以尝试使用类似

的库。为什么不设置this.copyOfColumns=JSON.stringify(Object.assign([],this.columns));尝试了之后,得到了完全相同的错误
  @Input()
  set gridColumns(gridColumnsArr: Array<object>) {
    console.log('gridColumnsArr');
    console.log(gridColumnsArr);
    this.columns = this.sortActiveAndInactiveColumns(gridColumnsArr);
    console.log('this.columns');
    console.log(this.columns);
    this.copyOfColumns = JSON.parse(JSON.stringify(Object.assign([], this.columns)));
    console.log('this.copyOfColumns');
    console.log(this.copyOfColumns);
  }