Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.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
Javascript JSON.stringify正在忽略数据,返回{}_Javascript_Json_Angular_Typescript - Fatal编程技术网

Javascript JSON.stringify正在忽略数据,返回{}

Javascript JSON.stringify正在忽略数据,返回{},javascript,json,angular,typescript,Javascript,Json,Angular,Typescript,我是javascript新手,在使用JSON.stringify()转换对象时遇到了一个问题 代码如下: const tmp4 = this.getrulecondition2(rule._id, key); //this returns the object that I need to convert to json string.. console.log(tmp4); //shows the output as below in the chrome console. //{}Comm

我是javascript新手,在使用
JSON.stringify()
转换对象时遇到了一个问题

代码如下:

const tmp4 = this.getrulecondition2(rule._id, key); //this returns the object that I need to convert to json string..

console.log(tmp4); //shows the output as below in the chrome console.
//{}Command: "ps"Match: "test"Name: "test"Regex: "test"Terminal: "test"__proto__: Object

var str = JSON.stringify(tmp4);
console.log(str); //shows {} in the console log.

我想知道它是否在从函数return获取对象之前转换stringify语句。如何确保它只在获得函数结果后才进入下一行?

答案几乎肯定取决于
this.getrulecondition2()
的功能,但您没有发布它。来自
console.log(tmp4)的输出-您确定这是准确的输出吗?看起来非常错误。我怀疑这是一个异步问题。对象是空的,但是
console.log
直到稍后填充对象后才会执行。请将
getrulecondition2
的代码添加到问题中看起来不是有效的JSON答案几乎可以肯定取决于
this.getrulecondition2()
做了什么,但您没有发布它-您确定这是准确的输出吗?看起来非常错误。我怀疑这是一个异步问题。对象是空的,但是
console.log
直到稍后填充对象后才会执行。请将
getrulecondition2
的代码添加到问题中看起来不像有效的json