如何在nodejs中为我的响应JSON输出中的值提供新行?



我正在创建一个instagram刮板使用nodeJs。我在刮痧JSOn格式的链接,并显示在页面上,但所有的链接都在一行。我需要区分JSON中不同行的不同值。我尝试过JSON。stringify和JSON。解析,但它不工作任何解决方案

输入:{"title":"Astronomy (@astronomyforum) posted on Instagram: “An interesting question to think about is what would happen if the moon exploded? 😨🌗 Imagine the moon exploding and what that would look…” • Jul 26, 2021 at 6:36pm UTC","url":"https://www.instagram.com/p/CRzPjbRqxim/","file":"video","video_link":"https://instagram.fdel2-2.fna.fbcdn.net/v/t50.2886-16/225510060_149101203965285_678675776161943659_n.mp4?_nc_ht=instagram.fdel2-2.fna.fbcdn.net&_nc_cat=105&_nc_ohc=66WeoAC3o4gAX9Oh7VW&edm=AABBvjUBAAAA&ccb=7-4&oe=610E2F5C&oh=efc2bc202dd59cb4a08744321c26f1f9&_nc_sid=83d603"}

输出:

{
"title":"Astronomy (@astronomyforum) posted on Instagram: “An interesting question to think about is what would happen if the moon exploded? 😨🌗  Imagine the moon exploding and what that would look…” • Jul 26, 2021 at 6:36pm UTC",
"url":"https://www.instagram.com/p/CRzPjbRqxim/",
"file":"video",
"video_link":"https://instagram.fdel2-2.fna.fbcdn.net/v/t50.2886-16/225510060_149101203965285_678675776161943659_n.mp4?_nc_ht=instagram.fdel2-2.fna.fbcdn.net&_nc_cat=105&_nc_ohc=66WeoAC3o4gAX9Oh7VW&edm=AABBvjUBAAAA&ccb=7-4&oe=610E2F5C&oh=efc2bc202dd59cb4a08744321c26f1f9&_nc_sid=83d603"
}

这是我的代码:

let video_link = $('meta[property="og:video"]').attr('content');
let file = $('meta[property="og:type"]').attr('content');
let url = $('meta[property="og:url"]').attr('content');
let title = $('meta[property="og:title"]').attr('content');
res.status(200).json({ title, url, file, video_link});

这是关于浏览器的,你必须为Json浏览器添加任何扩展。例如,这是为chrome;

https://chrome.google.com/webstore/detail/json-viewer/gbmdgpbipfallnflgajpaliibnhdgobh?hl=en

您可以尝试在JSON.stringify中添加第三个参数

:

let json = { uno: 1, dos: 2 };
let newlineJson = JSON.stringify(json, null, 't');

newlineJson=

{
"uno": 1,
"dos": 2
}

然后将其与pre标签组合,以便浏览器相应地显示

res.status(200).send(`<pre>${JSON.stringify({ title, url, file, video_link}, null, 2)</pre>`);

相关内容

  • 没有找到相关文章

最新更新