【发布时间】:2020-08-12 23:09:31
【问题描述】:
我有一个问题,过去几天我和我的朋友 google 一起试图回答。这是我目前正在处理的一个项目的代码,我正在尝试与两个 API 交互。
您在此处看到的是使用 GOT 库格式调用第一个 API 以接收 JSON 响应。
var products
//Printify call for products list
(async () => {
try{
const list = await redd('shops/shopId/products.json');
//Catch the Data array and save it into the variable products
var obj = new JSONObject(response);
products = obj.getJSONArray("data");
}
catch(error) {
}
})();
//Print the variable products to the console
console.log(products)
我从响应中创建一个新的 JSONObject 并从该响应中获取数据数组并将其放入在此函数之外定义的变量产品中。最后我试图将变量打印到控制台。
最终,我需要获取该“数据”数组并解析其中的特定项目(即title: , description: , images:)并将其作为值传递给下一个 API。
目前我从控制台收到“未定义”响应。不知道我做错了什么,希望我能得到一些帮助或指导。任何事情都非常感谢,提前谢谢大家!
【问题讨论】:
-
什么是 JSONObject?
标签: javascript node.js json rest