2017-05-01 16 views
0

requestを使用してAPI呼び出しを行っています。リクエストノードapiからの応答を取得

すべてが正常に動作していますが、実際には応答からresultsを取得できません。この

app.get('/events/:query', (req, res) => { 

    request('http://www.skiddle.com/api/v1/events/search/?api_key=*****&keyword=elvis', (error, response, body) => { 
     res.setHeader('Content-Type', 'application/json'); 
     res.send(body); 
    }); 

}); 

res.send(body);は、以下のように見えるように

私のコードが見えます。誰も私がresultsにアクセスする方法を知っていますか?私はbody.resultsを試しましたが、これは動作しません。

{ 
    "error":0, 
    "totalcount":"25", 
    "pagecount":20, 
    "results":[ 
     { 
     "id":"12958041", 
     "EventCode":"FOOD", 
     "eventname":"Elvis Tribute", 
     "cancelled":"0", 
     "venue":{ 
      "id":72198, 
      "name":"Simla Restaurant", 
      "address":"5a Watling Street", 
      "town":"Dordon", 
      "postcode":"B78 1SS", 
      "country":"GB", 
      "phone":"00000000000", 
      "latitude":52.597021, 
      "longitude":-1.6113712, 
      "type":"Restaurant", 
      "rating":0 
     }, 
     "imageurl":"https:\/\/d31fr2pwly4c4s.cloudfront.net\/2\/2\/a\/950766_0_elvis-tribute_th.jpg", 
     "largeimageurl":"https:\/\/d31fr2pwly4c4s.cloudfront.net\/2\/2\/a\/950766_0_elvis-tribute.jpg", 
     "link":"http:\/\/www.skiddle.com\/whats-on\/Birmingham\/Simla-Restaurant\/Elvis-Tribute\/12958041\/", 
     "date":"2017-05-10", 
     "startdate":"2017-05-10T19:00:00+00:00", 
     "enddate":"2017-05-10T23:00:00+00:00", 
     "description":"Elvis Tribute evening ", 
     "openingtimes":{ 
      "doorsopen":"19:00", 
      "doorsclose":"23:00", 
      "lastentry":"" 
     }, 
     "minage":"0", 
     "imgoing":null, 
     "goingtocount":"0", 
     "tickets":false, 
     "entryprice":"Ticket: GBP 26.95", 
     "rep":{ 
      "enabled":null 
     } 
     }, 
     { 
     "id":"12948859", 
     "EventCode":"COMEDY", 
     "eventname":"NCFComedy present The Elvis Dead - Part of Derby Comedy Fest", 
     "cancelled":"0", 
     "venue":{ 
      "id":77454, 
      "name":"Carnero Lounge", 
      "address":"10 St Peter's Gate", 
      "town":"Derby", 
      "postcode":"DE1 1SH", 
      "country":"GB", 
      "phone":"", 
      "latitude":52.9208847, 
      "longitude":-1.4767019, 
      "type":"bar", 
      "rating":0 
     }, 
     "imageurl":"https:\/\/d31fr2pwly4c4s.cloudfront.net\/5\/c\/c\/946899_2_ncfcomedy-present-the-elvis-dead-part-of-derby-comedy-fest_th.jpg", 
     "largeimageurl":"https:\/\/d31fr2pwly4c4s.cloudfront.net\/5\/c\/c\/946899_2_ncfcomedy-present-the-elvis-dead-part-of-derby-comedy-fest.jpg", 
     "link":"http:\/\/www.skiddle.com\/whats-on\/Derby\/Carnero-Lounge\/NCFComedy-present-The-Elvis-Dead---Part-of-Derby-Comedy-Fest\/12948859\/", 
     "date":"2017-05-11", 
     "startdate":"2017-05-11T19:00:00+00:00", 
     "enddate":"2017-05-11T20:00:00+00:00", 
     "description":"Rob Kemp: The Elvis Dead\r\nPart of Derby Comedy Festival", 
     "openingtimes":{ 
      "doorsopen":"19:00", 
      "doorsclose":"20:00", 
      "lastentry":"" 
     } 
     } 
    } 

答えて

0

まず、あなたの体を解析する必要があります。 これを試してください。

try { 
    body = JSON.parse(body); 
} 
catch(err) { 
    console.log(err); 
} 
res.send(body.results); 
関連する問題