当前位置: 首页 > 知识库问答 >
问题:

在节点js中解析json?[重复]

蒋乐意
2023-03-14

我正在将JSON数据从我的客户端发送到我的服务器端,然后我试图从json中提取标题值。我尝试了许多不同的方法来解析json,但我无法找出正确的方法。有人能建议我该怎么办吗?我的客户端片段

  if (response.status == 'ok') {
                $.ajax({
                    type: 'POST',
                    url: '/home',
                    data: JSON.stringify(info),
                    success: function (data) {


                    },
                    error: function (data) {
                        console.log('error');
                        console.log(data)
                    }
                });
            }

服务器端-

app.post("/home",function(req,res)
{

    var name = req.body;
    console.log("name",name);

});

我服务器端的JSON数据-

{ '[{"title":"Queen\'s Speech outlines UK government\'s agenda at troubled time for May","pubDate":"2017-06-21 12:28:31","link":"http://www.cnn.com/2017/06/21/europe/queens-speech-theresa-may/index.html","guid":"http://www.cnn.com/2017/06/21/europe/queens-speech-theresa-may/index.html","author":"","thumbnail":"","description":"Britain\'s embattled Prime Minister Theresa May\'s attempt to lead a minority government starts in earnest Wednesday amid a backdrop of terror attacks and the fire at Grenfell Tower, one of the country\'s worst disasters for a generation.","content":"Britain\'s embattled Prime Minister Theresa May\'s attempt to lead a minority government starts in earnest Wednesday amid a backdrop of terror attacks and the fire at Grenfell Tower, one of the country\'s worst disasters for a generation.","enclosure":{"link":"http://i2.cdn.turner.com/cnnnext/dam/assets/170621115550-04-queen-opening-parliament-0621-super-169.jpg"},"categories":': [ 'http//cnnios-f.akamaihd.net/i/cnn/big/test/360/parliament_normal_day_vr_48770_,768x432_1500,960x540_2500,1280x720_3500,1920x1080_5904,.mp4.csmil/master.m3u8","guid":"cnn://360video=http://cnnios-f.akamaihd.net/i/cnn/big/test/360/parliament_normal_day_vr_48770_,768x432_1500,960x540_2500,1280x720_3500,1920x1080_5904,.mp4.csmil/master.m3u8","author":"","thumbnail":"","description":"","content":"","enclosure":{"link":"http://i2.cdn.turner.com/cnnnext/dam/assets/170322122603-parliament-normal-day-full-360-super-169.jpg"},"categories":[]},{"title":"Brussels Central Station attack suspect identified","pubDate":"2017-06-21 10:35:42","link":"http://www.cnn.com/2017/06/21/europe/brussels-train-station-attack/index.html","guid":"http://www.cnn.com/2017/06/21/europe/brussels-train-station-attack/index.html","author":"","thumbnail":"","description":"Belgian authorities now know the identity of a man who was fatally shot at Brussels Central Station after a failed bombing, a spokeswoman for the Minister of Security and Home Affairs told CNN on Wednesday.","content":"Belgian authorities now know the identity of a man who was fatally shot at Brussels Central Station after a failed bombing, a spokeswoman for the Minister of Security and Home Affairs told CNN on Wednesday.","enclosure":{"link":"http://i2.cdn.turner.com/cnnnext/dam/assets/170620161931-09-brussels-train-station-incident-0620-super-169.jpg"},"categories":[]},{"title":"Duterte pledges to rebuild ISIS-infested Philippines city","pubDate":"2017-06-21 09:14:49","link":"http://www.cnn.com/2017/06/21/asia/philippines-isis-marawi-duterte/index.html","guid":"http://www.cnn.com/2017/06/21/asia/philippines-isis-marawi-duterte/index.html","author":"","thumbnail":"","description":"Philippines President Rodrigo Duterte begged forgiveness Tuesday for declaring martial law in Mindanao island and vowed to rebuild Marawi, the battle-scarred city at the heart of nearly four weeks of fighting between Philippines forces and ISIS-affiliated militants.","content":"Philippines President Rodrigo Duterte begged forgiveness Tuesday for declaring martial law in Mindanao island and vowed to rebuild Marawi, the battle-scarred city at the heart of nearly four weeks of fighting between Philippines forces and ISIS-affiliated militants.","enclosure":{"link":"http://i2.cdn.turner.com/cnnnext/dam/assets/170620204732-duterte-marawi-june-20-super-169.jpg"},"categories":[]},{"title":"Oscar legend Daniel Day-Lewis retiring from acting","pubDate":"2017-06-21 09:48:48","link":"http://www.cnn.com/2017/06/21/entertainment/daniel-day-lewis-retires-acting/index.html","guid":"http://www.cnn.com/2017/06/21/entertainment/daniel-day-lewis-retires-acting/index.html","author":"","thumbnail":"","description":"Actor Daniel Day-Lewis has officially announced his retirement.","content":"Actor Daniel Day-Lewis has officially announced his retirement.","enclosure":{"link":"http://i2.cdn.turner.com/cnnnext/dam/assets/170621163711-daniel-day-lewis-super-169.jpg"},"categories":[]},{"title":"India arrests 15 for celebrating Pakistan cricket victory","pubDate":"2017-06-21 10:43:38","link":"http://www.cnn.com/2017/06/21/asia/india-arrest-pakistan-cricket/index.html","guid":"http://www.cnn.com/2017/06/21/asia/india-arrest-pakistan-cricket/index.html","author":"","thumbnail":"","description":"Fifteen Indian men are facing lengthy jail sentences for allegedly cheering on the Pakistan cricket team.","content":"Fifteen Indian men are facing lengthy jail sentences for allegedly cheering on the Pakistan cricket team.","enclosure":{"link":"http://i2.cdn.turner.com/cnnnext/dam/assets/170619090748-pakistan-celebrate-super-169.jpg"},"categories":[]},{"title":"After four attacks, how will the UK fight terror?","pubDate":"2017-06-21 11:46:48","link":"http://www.cnn.com/videos/world/2017/06/21/uk-terror-attacks-police-government-response-jlm-orig.cnn","guid":"http://www.cnn.com/videos/world/2017/06/21/uk-terror-attacks-police-government-response-jlm-orig.cnn","author":"","thumbnail":"","description":"With the nation on high alert, British security services are hard at work to prevent future attacks.","content":"With the nation on high alert, British security services are hard at work to prevent future attacks.","enclosure":{"link":"http://i2.cdn.turner.com/cnnnext/dam/assets/170621101544-uk-terror-police1-super-169.jpg"},"categories":[]},{"title":"Chelsea Clinton: Bannon \'fat shamed\' Spicer","pubDate":"2017-06-21 06:21:55","link":"http://www.cnn.com/2017/06/20/politics/chelsea-clinton-fat-shaming-sean-spicer-steve-bannon/index.html","guid":"http://www.cnn.com/2017/06/20/politics/chelsea-clinton-fat-shaming-sean-spicer-steve-bannon/index.html","author":"","thumbnail":"","description":"The punchline, for lack of a better word, in a piece in The Atlantic on the much-maligned decay of the White House press is a text message, presumably joking, from White House adviser Steven Bannon to a reporter explaining why Sean Spicer has spent less and less time in front of cameras at the podium.","content":"The punchline, for lack of a better word, in a piece in The Atlantic on the much-maligned decay of the White House press is a text message, presumably joking, from White House adviser Steven Bannon to a reporter explaining why Sean Spicer has spent less and less time in front of cameras at the podium.","enclosure":{"link":"http://i2.cdn.turner.com/cnnnext/dam/assets/161104201013-chelsea-clinton-oct-17-super-169.jpg"},"categories":[]},{"title":"House Russia probe digs into voter roll hacks","pubDate":"2017-06-21 08:04:20","link":"http://www.cnn.com/2017/06/21/politics/jeh-johnson-congress-hearing/index.html","guid":"http://www.cnn.com/2017/06/21/politics/jeh-johnson-congress-hearing/index.html","author":"","thumbnail":"","description":"House investigators will examine on Wednesday Russia\'s attempts to hack into state elections systems with former Department of Homeland Security Secretary Jeh Johnson before the House intelligence committee.","content":"House investigators will examine on Wednesday Russia\'s attempts to hack into state elections systems with former Department of Homeland Security Secretary Jeh Johnson before the House intelligence committee.","enclosure":{"link":"http://i2.cdn.turner.com/cnnnext/dam/assets/151207100809-jeh-johnson-defense-one-00001404-super-169.jpg"},"categories":[]},{"title":"Trump: Death of US student held in N. Korea was \'disgrace\'","pubDate":"2017-06-20 18:41:36","link":"http://www.cnn.com/2017/06/20/politics/trump-otto-warmbier-north-korea/index.html","guid":"http://www.cnn.com/2017/06/20/politics/trump-otto-warmbier-north-korea/index.html","author":"","thumbnail":"","description":"President Donald Trump on Tuesday suggested that Otto Warmbier, the American who died days after his release from North Korea, would still be alive if he had been released sooner.","content":"President Donald Trump on Tuesday suggested that Otto Warmbier, the American who died days after his release from North Korea, would still be alive if he had been released sooner.","enclosure":{"link":"http://i2.cdn.turner.com/cnnnext/dam/assets/170615120947-warmbier-coma-split-restricted-super-169.jpg"},"categories":[]},{"title":"Warmbier family declines autopsy","pubDate":"2017-06-21 11:33:35","link":"http://www.cnn.com/2017/06/20/health/otto-warmbier-autopsy/index.html","guid":"http://www.cnn.com/2017/06/20/health/otto-warmbier-autopsy/index.html","author":"","thumbnail":"","description":"The family of American college student Otto Warmbier objected to an autopsy, leaving the former North Korea detainee\'s official cause of death a mystery for the time being.","content":"The family of American college student Otto Warmbier objected to an autopsy, leaving the former North Korea detainee\'s official cause of death a mystery for the time being.","enclosure":{"link":"http://i2.cdn.turner.com/cnnnext/dam/assets/160122111735-01-otto-warmbier-super-169.jpg"},"categories":[]}]' ] }

共有1个答案

吕越彬
2023-03-14

JSON。作语法分析

app.post("/home",function(req,res){
   var data = JSON.parse(req.body);
   console.log("name",data.name);
});
 类似资料:
  • 问题内容: 我想解析JavaScript中的JSON字符串。响应就像 我怎样才能获得的值,并从这个? 问题答案: 在JavaScript中解析JSON的标准方法是 JSON.parse() 该JSONAPI是在ES5(2011)中引入的,此后按市场份额和Node.js在超过99%的浏览器中已实现。它的用法很简单: 唯一无法使用的时间是你是否在为旧版浏览器编程,例如IE 7(2006),IE 6(2

  • 我创建了一个小节点应用程序,从GitHub jobs API获取作业。我正在使用模块来完成此操作。您可以看到下面的代码: 如果您能帮助打印JSON对象,我将不胜感激,目前它只打印。

  • 人js main.js 当运行main时。我犯了个错误 谢啦

  • 我试图实现我的RestAPI的JWE。我遇到了以下实现JWE的节点库。然而,库缺乏关于如何使用JSON Web密钥(JWK)(JSON对象)的留档,这有助于密钥管理模式。JWE留档内容如下: 确定要使用的内容加密密钥值的方法。用于确定CEK值的每个算法使用特定的密钥管理模式。本规范采用的密钥管理模式包括密钥加密、密钥包装、直接密钥协议、密钥协议与密钥包装以及直接加密。 所以我想知道我应该如何将JW

  • 我试图在spring Boot中将在JSON中得到的响应存储在数据库中。但是当它显示时 这是我的JSON响应 我的getEmployees()方法 这是我得到的错误 我想不出是什么造成了这个错误,如果有人能给我一些建议,那将会很有帮助

  • 我有一个简单的服务器,我只是在发布时将json打印到屏幕上。这是我的代码: 然后我用curl将一个JSON放到服务器上: 但是服务器只是打印 我做错了什么?