无法打印来自 Yelp fusion 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) 时都未定义。给出了什么?

我猜主体 "object" 实际上是一个字符串。尝试添加

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

如果它说 "Type: string" 尝试

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