JSON.stringify缺少的属性 [英] JSON.stringify missing properties

查看:359
本文介绍了JSON.stringify缺少的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个自定义的console.error函数,以便每次发生错误时,我都会收到一封电子邮件.要在电子邮件正文中发送错误,请使用JSON.stringify().问题在于它缺少某些属性.请参见下面的两个图像:

I'm writing a custom console.error function so that every time an error occurs I receive an e-mail. To send the error in e-mail body I use JSON.stringify(). The problem is that it is missing some properties. See the two images below:

电子邮件:

在控制台中:

这是我使用JSON.stringfy的方式:

And here is how I use JSON.stringfy:

JSON.stringify(arguments, null, 4);

我一直在搜索,发现有相同问题的人,但到目前为止没有答案.

I've been googling and found people with the same issue, but so far no answer.

可以帮我吗?

推荐答案

请参见.

由于您的Error对象位于另一个对象内,因此您可能必须使用2个stringify调用:

Since your Error object is inside another object, you might have to use 2 stringify calls :

JSON.stringify({
0: ...,
1: JSON.stringify({errorObject, ["message", "arguments", "type", "name"]}),
});

或者类似的东西.

如果我正确地获得了此信息,则您缺少的信息在Error对象中.我的猜测是JSON.stringify为其中的每个对象调用.toString().但是,对于一个Error对象,也许toString()函数不会返回您想要的所有信息,而不是您在控制台中看到的所有信息.

If I'm getting this correctly, the informations you are lacking are in the Error object. My guess would be that JSON.stringify calls .toString() for each object inside it. Though, for an Error object, maybe the toString() function doesn't return ALL the informations you want, versus what you see in the console.

也许您必须调用错误对象的.description ()自己发挥作用.

Maybe you'll have to call the Error object's .description() function yourself.

这篇关于JSON.stringify缺少的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆