2017-06-21 14 views
0

JSONデータをクライアント側からサーバー側に送信していますが、JSONからタイトル値を抽出しようとしています。私はjsonを解析するためにさまざまな方法を試しましたが、私はそれを行う正しい方法を理解することができません。誰かが私に何をすべきかを親切に提案できますか?私のクライアント側の スニペットノードjsの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":[]}]' ] } 
+0

使用 'JSON.parse'機能 – dloeda

答えて

0

JSON.parse?

app.post("/home",function(req,res){ 
    var data = JSON.parse(req.body); 
    console.log("name",data.name); 
}); 
+0

これは実際のOPの質問、コードが何をするかの通常簡単な説明を(そして、それは問題を修正する方法)すべての(ほとんどの新しい開発者)によって歓迎される答えるかもしれませんが - あなたの答えを更新することを考えてください。 – ochi

+0

@ oi OPは重複した説明を見つけることができます。この質問はすぐに削除されます... –

関連する問題