[英]Making JSON code 'cleanly displayed' on an HTML page
I'm trying to get this code cleaner, it does display on the html page. 我正在尝试使此代码更清洁,它确实显示在html页面上。
app.get("/web/users", function(req, res) {
var users = app.models.users.model('User');
users.find({}).lean().exec(function(err, result){
res.write(JSON.stringify(result));
res.end();
This does work, and it lists something like this... 这确实有效,并且列出了类似的内容...
[{"_id":"...","name":"Justin","phonenumber":"5555555555","useSMS":true,"callerId":["..."],"PIN":"..."}] [{ “_id”: “... ”“ 名 ”:“ 贾斯汀”, “PHONENUMBER”: “5555555555”, “useSMS”:真正的 “来电显示”: “... ”],“ PIN”: “...”}]
Now, I would like this code to display like this... 现在,我希望这段代码像这样显示...
Justin 5555555555 贾斯汀5555555555
If I understood correctly and you want your json pretty-printed, here: 如果我理解正确,并且您想要漂亮地打印您的json,请在此处:
res.write(JSON.stringify(result, null, 2));
That will indent your JSON hierarchically using 2 spaces. 这将使用2个空格分层缩进JSON。
EDIT: re-reading with Mouseroot's comment, I think what you actually want is: 编辑:用Mouseroot的评论重新阅读,我认为您真正想要的是:
res.write(result.name + ' ' + result.phonenumber);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.