您如何在Node.js中记录JSON对象的内容? [英] How do you log content of a JSON object in Node.js?
本文介绍了您如何在Node.js中记录JSON对象的内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以打印对象内容,例如Node.js中的方法和属性?
Is it possible to print an objects contents e.g. methods and attributes in Node.js?
此刻,我正在尝试打印会话对象并获得以下内容:
At the moment I'm trying to print the session object and get the following:
console.log("Session:" + session);
> Session:[object Object]
也许与PHP中的print_r(array)相似,或者在Java中使用.toString.
Maybe in a similar way to print_r(array) in PHP, or using .toString in Java.
推荐答案
尝试以下方法:
console.log("Session: %j", session);
如果该对象可以转换为JSON,则可以使用.
If the object could be converted into JSON, that will work.
这篇关于您如何在Node.js中记录JSON对象的内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文