gpt4 book ai didi

javascript - 在 HTML 页面上制作 JSON 代码 'cleanly displayed'

转载 作者:行者123 更新时间:2023-11-30 17:36:09 25 4
gpt4 key购买 nike

我正在尝试让这段代码更清晰,它确实显示在 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();

这确实有效,它列出了类似这样的内容......

[{"_id":"...","name":"Justin","phonenumber":"5555555555","useSMS":true,"callerId":["..."],"PIN":"..."}]

现在,我希望这段代码像这样显示...

贾斯汀 5555555555

最佳答案

如果我理解正确并且你希望你的 json 打印得漂亮,这里:

res.write(JSON.stringify(result, null, 2));

这将使用 2 个空格分层缩进您的 JSON。

编辑:重新阅读 Mouseroot 的评论,我认为您真正想要的是:

res.write(result.name + ' ' + result.phonenumber);

关于javascript - 在 HTML 页面上制作 JSON 代码 'cleanly displayed',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21999507/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com