简体   繁体   English

Google Apps 脚本 JSON.Parse 在调试时导致“无法连接到服务器”

[英]Google Apps Script JSON.Parse causing 'could not connect to server' on debug

I'm by no means what I would call a "developer" but dabble quite a bit.我绝不是我所谓的“开发人员”,而是涉猎不少。 I'm working on some Apps Script code to query an API and push the results into SQL.我正在编写一些应用程序脚本代码来查询 API 并将结果推送到 SQL 中。 I have most of the bits working but I've noticed that while I'm debugging in the Apps Script editor, when I step into the following line of code, the editor throws the "could not connect to server message at the top.我有大部分的工作,但我注意到,当我在 Apps 脚本编辑器中调试时,当我进入以下代码行时,编辑器会在顶部抛出“无法连接到服务器消息。


    var response = UrlFetchApp.fetch(clientApiURL,options);
    var resultSet = JSON.parse(response.getContentText());  <-- this is the line that is crashing the IDE

Anyone know how to better debug this?任何人都知道如何更好地调试这个? When I'm not debugging it, the code seems to behave and function properly.当我不调试它时,代码似乎正常运行并且 function 正确。 But with this API, not all objects are formatted the same way, so I like to use the debugger to inspect them.但是有了这个 API,并不是所有的对象都以相同的方式格式化,所以我喜欢使用调试器来检查它们。 I can do that when the editor crashes.当编辑器崩溃时,我可以这样做。

Any help/insight would be super appreciated.任何帮助/见解将不胜感激。 I've also pasted below the value of response.getContentText()我还粘贴在 response.getContentText() 的值下方


    {"result":{"lead":[{"id":"332","accountID":null,"ownerID":null,"companyName":"","title":null,"firstName":"RYAN","lastName":"CAVANAUGH","street":null,"city":null,"country":null,"state":null,"zipcode":null,"emailAddress":"email@here.com","website":null,"phoneNumber":null,"officePhoneNumber":null,"phoneNumberExtension":null,"mobilePhoneNumber":null,"faxNumber":null,"description":null,"campaignID":"789934082","trackingID":"202003_5e6fa18a87853a69eb306910","industry":null,"active":"1","isQualified":"1","isContact":"1","isCustomer":"1","status":"4","updateTimestamp":"2020-05-08 20:24:48","createTimestamp":"2020-05-03 20:23:29","leadScoreWeighted":"23","leadScore":"26","isUnsubscribed":"0","leadStatus":"customer","persona":"","product_5e554b933fb5b":""}]},"error":null,"id":"5222020","callCount":"215","queryLimit":"50000"}

This will reproduce the error:这将重现错误:

function test(){
 var obj={"result":{"lead":[{"id":"332","accountID":null,"ownerID":null,"companyName":"","title":null,"firstName":"RYAN","lastName":"CAVANAUGH","street":null,"city":null,"country":null,"state":null,"zipcode":null,"emailAddress":"email@here.com","website":null,"phoneNumber":null,"officePhoneNumber":null,"phoneNumberExtension":null,"mobilePhoneNumber":null,"faxNumber":null,"description":null,"campaignID":"789934082","trackingID":"202003_5e6fa18a87853a69eb306910","industry":null,"active":"1","isQualified":"1","isContact":"1","isCustomer":"1","status":"4","updateTimestamp":"2020-05-08 20:24:48","createTimestamp":"2020-05-03 20:23:29","leadScoreWeighted":"23","leadScore":"26","isUnsubscribed":"0","leadStatus":"customer","persona":"","product_5e554b933fb5b":""}]},"error":null,"id":"5222020","callCount":"215","queryLimit":"50000"} 
 var resultSet = JSON.parse(obj);
}

Taking a look at the problem:看问题:

function test(){
 var obj={"result":{"lead":[{"id":"332","accountID":null,"ownerID":null,"companyName":"","title":null,"firstName":"RYAN","lastName":"CAVANAUGH","street":null,"city":null,"country":null,"state":null,"zipcode":null,"emailAddress":"email@here.com","website":null,"phoneNumber":null,"officePhoneNumber":null,"phoneNumberExtension":null,"mobilePhoneNumber":null,"faxNumber":null,"description":null,"campaignID":"789934082","trackingID":"202003_5e6fa18a87853a69eb306910","industry":null,"active":"1","isQualified":"1","isContact":"1","isCustomer":"1","status":"4","updateTimestamp":"2020-05-08 20:24:48","createTimestamp":"2020-05-03 20:23:29","leadScoreWeighted":"23","leadScore":"26","isUnsubscribed":"0","leadStatus":"customer","persona":"","product_5e554b933fb5b":""}]},"error":null,"id":"5222020","callCount":"215","queryLimit":"50000"} 
 var resultSet = JSON.parse(JSON.stringify(obj));
}

but so what the point of the parse is to return an object from a string not from object.但是解析的重点是从不是来自 object 的字符串中返回 object。

But I do see the problem.但我确实看到了问题。 'Cannot connect to the server' '无法连接到服务器'

I found that this does seem to work know:我发现这似乎确实有效知道:

function test(){
 var obj='{"result":{"lead":[{"id":"332","accountID":"","ownerID":"","companyName":"","title":"","firstName":"RYAN","lastName":"CAVANAUGH","street":"","city":"","country":"","state":"","zipcode":"","emailAddress":"email@here.com","website":"","phoneNumber":"","officePhoneNumber":"","phoneNumberExtension":"","mobilePhoneNumber":"","faxNumber":"","description":"","campaignID":"789934082","trackingID":"202003_5e6fa18a87853a69eb306910","industry":"","active":"1","isQualified":"1","isContact":"1","isCustomer":"1","status":"4","updateTimestamp":"2020-05-08 20:24:48","createTimestamp":"2020-05-03 20:23:29","leadScoreWeighted":"23","leadScore":"26","isUnsubscribed":"0","leadStatus":"customer","persona":"","product_5e554b933fb5b":""}]},"error":"","id":"5222020","callCount":"215","queryLimit":"50000"}'; 
 var resultSet = JSON.parse(obj);
 var end="is near";//I just put this here to have a place to stop with debugger running
}

I replaced all of the null s with "".我用“”替换了所有 null 。

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

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