[英]Can't print business information from Yelp fusion api
I am using the yelp fusion api to search for a type of business in a location. 我正在使用yelp融合api在位置中搜索一种业务。 I can print the whole body correctly but when I try to log just the businesses or a specific parameter of a business I get undefined. 我可以正确打印整个正文,但是当我尝试仅记录业务或业务的特定参数时,却无法定义。
For example, this prints the businesses: 例如,这将打印业务:
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(body);
res.render('index');
});
I get a large object which looks something like this: 我得到一个看起来像这样的大物体:
{"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": ""}
However, when I try console.log(body.businesses)
or console.log(body.businesses[0].name)
both undefined. 但是,当我尝试console.log(body.businesses)
或console.log(body.businesses[0].name)
都未定义。 What gives? 是什么赋予了?
I'm going to guess that the body "object" is actually a string. 我将猜测主体“对象”实际上是一个字符串。 Try adding 尝试添加
console.log("Type:", typeof body)
and if it says "Type: string" try 如果显示“类型:字符串”,请尝试
const bodyObj = JSON.parse(body);
console.log(bodyObj.businesses);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.