繁体   English   中英

无法从Yelp融合API打印业务信息

[英]Can't print business information from Yelp fusion api

我正在使用yelp融合api在位置中搜索一种业务。 我可以正确打印整个正文,但是当我尝试仅记录业务或业务的特定参数时,却无法定义。

例如,这将打印业务:

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

我得到一个看起来像这样的大物体:

{"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": ""}

但是,当我尝试console.log(body.businesses)console.log(body.businesses[0].name)都未定义。 是什么赋予了?

我将猜测主体“对象”实际上是一个字符串。 尝试添加

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

如果显示“类型:字符串”,请尝试

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM