JSON.stringify返回& quot; [object Object]& quot;而不是对象的内容 [英] JSON.stringify returns "[object Object]" instead of the contents of the object

查看:137
本文介绍了JSON.stringify返回& quot; [object Object]& quot;而不是对象的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里创建一个JavaScript对象并将其转换为JSON字符串,但是 JSON.stringify 在这种情况下,返回"[object Object]" ,而不显示对象的内容.如何解决此问题,以便JSON字符串实际上包含对象的内容?

Here I'm creating a JavaScript object and converting it to a JSON string, but JSON.stringify returns "[object Object]" in this case, instead of displaying the contents of the object. How can I work around this problem, so that the JSON string actually contains the contents of the object?

var theObject = {name:{firstName:"Mark", lastName:"Bob"}};
alert(JSON.stringify(theObject.toString())); //this alerts "[object Object]"

推荐答案

使用 alert(JSON.stringify(theObject));

这篇关于JSON.stringify返回& quot; [object Object]& quot;而不是对象的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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