【发布时间】:2018-01-25 07:47:12
【问题描述】:
我有 fetch() 设置来使用他们的 API 从 GotoWebinar 检索历史网络研讨会详细信息。它返回一个具有这种结构的 JSON 体,一个对象数组:
[{ “网络研讨会密钥”:5653814518315977731, “网络研讨会ID”:“562189251”, “主题”:“示例网络研讨会”, “组织者密钥”:100000000000331530 }, { “网络研讨会密钥”:9999814518315977731, “网络研讨会ID”:“999989251”, “主题”:“示例网络研讨会”, “组织者密钥”:999900000000331530 }]
我的代码在 Zapier 动作(node.js)中实现,重要的部分如下所示:
//Handle errors from fetch call
function handleFetchStatus(response){
console.log('Fetch Response Status: ' + response.status);
switch(response.status){
case 200: //Request executed properly
break;
default:
throw Error(response.status + ':' + JSON.stringify(response));
}
return response.json();
}
function handleFetchBody(oResponse){
if (oResponse) {
console.log('handleFetchBody: ' + JSON.stringify(oResponse));
}
callback(null, oResponse);
}
//Send POST request.
fetch(getFetchURL(), getFetchOptions())
.then(handleFetchStatus)
.then(handleFetchBody)
.catch(function(error) {
callback(error);
});
我遇到的问题是“webinarKey”这个长数字被从“5653814518315977731”截断为“5653814518315978000”。我相信是 json() 函数不能处理大量数字。
我怎样才能阻止这种情况?
我相信我需要在使用 json() 之前将 webinarKey 转换为字符串,但我不确定如何访问对象的所有元素。这在 fetch 响应中是否可能。
【问题讨论】:
标签: json node.js long-integer fetch-api truncated