Javascript JSON.stringify正在忽略数据,返回{}
我是javascript新手,在使用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
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