[英]SyntaxError: Unexpected token: T at json.parse
I'm new to google scripts and I want to fetch data from an URL when the user is logged in. I wrote some code but when I execute it the following error appears: SyntaxError: Unexpected token: T
我是google脚本的新手,我想在用户登录时从URL提取数据。我编写了一些代码,但是当我执行该代码时,会出现以下错误:
SyntaxError: Unexpected token: T
I know that this question has been asked before, but I can't find a solution for my issue... 我知道这个问题曾经被问过,但是我找不到解决问题的方法...
function myFunction() {
var endpoint = 'rule-sets';
var url = 'https://example.com/api/'+endpoint;
var restHeaders = {
'X-Application-Key': 'f3ez1a48f06838b7238z20cff80e010bf0c42cfp',
'Authorization':'Bearer bm9scnVuMDQ4Z2FvaWpvdHBqa2Y1djA5WWavTiElV5DyYjdxb3UxNnVyMzRoNWhsISPBmXNyZDFtMCYzMDk2JjE0NjE5MDI3NTYwODI=',
}
var options = {
'method' : 'get',
'headers': restHeaders,
'muteHttpExceptions': true,
};
var urlResponse = JSON.parse(UrlFetchApp.fetch(url, options));
Logger.log(urlResponse);
Logger.log(urlResponse.data.length);
}
Looking at https://developers.google.com/apps-script/reference/url-fetch/url-fetch-app#methods signature it looks like it will be this: 查看https://developers.google.com/apps-script/reference/url-fetch/url-fetch-app#methods签名,看起来会是这样:
var urlResponse = UrlFetchApp.fetch(url, options);
var jsonContent = JSON.parse(urlResponse.getContentText());
Logger.log(jsonContent);
Logger.log(jsonContent.data.length);
You were parsing the return value of fetch
which is an object. 您正在解析作为对象的
fetch
的返回值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.