2017-03-21 4 views
0

yelp fusion apiを使用してある場所のビジネスタイプを検索しています。私は全身を正しく印刷することができますが、ビジネスのログや特定のパラメータを記録しようとすると、私は定義されません。例えばYelp fusion apiのビジネス情報を印刷できません

、これはビジネスを出力します。

request(options, function (error, response, body) { 
     if (error) throw new Error(error); 
     console.log(body); 
     res.render('index'); 
    }); 

私は次のようになり、大きなオブジェクトを取得:私はconsole.log(body.businesses)またはconsole.log(body.businesses[0].name)両方未定義をしようとすると、しかし

{"total": 106, "businesses": [{"transactions": [], "phone": "+15409512483", "name": "The Rivermill", "display_phone": "(540) 951-2483", "price": "$", "review_count": 63, "rating": 4.0, "image_url": "https://s3-media3.fl.yelpcdn.com/bphoto/mQbuIZ9uRsXMwIW9UJiHsQ/o.jpg", "id": "the-rivermill-blacksburg", "distance": 511.45787585319994, "location": {"display_address": ["212 Draper Rd", "Blacksburg, VA 24060"], "city": "Blacksburg", "country": "US", "zip_code": "24060", "address1": "212 Draper Rd", "state": "VA", "address2": "", "address3": ""} 

を。何がありますか?

答えて

1

私はボディ "オブジェクト"が実際に文字列であると推測します。

console.log("Type:", typeof body) 

を追加してみてください、それは言うならば、 "タイプ:文字列を" 確かに問題だった

const bodyObj = JSON.parse(body); 
console.log(bodyObj.businesses); 
+0

を試してみてください。ああ!ありがとう! – andrewgi

関連する問題