简体   繁体   中英

Google Script: JSON.parse fails for no apparent reason

I have this function in google script that fetches a JSON from the web, but it fails when i try to execute it, citing:

SyntaxError: Unexcpected character in string: '\''

Script:

function getTheFeed(url){
    var response = UrlFetchApp.fetch(url);
    var json = response.getContentText();
    var Jdata = JSON.parse(json);
    Jdata = json;
    return Jdata;
}

I've tested the URL, by importing it in a string and doing JSON.parse on it, and i get no errors in Google Chrome.

Any other ideas?

UPDATE: After doing Logger.Log turns out the JSON is being cut after 8KB of response. Nothing conflicting at the place the request ends...

Still looking for a response...

Try to use alert(url) and see what you really get. It could be an escaping issue which sometimes browsers handle properly when you enter it directly in the address bar.

EDIT: Different browsers have different limits. But generally the limit is around 2,000 characters for the GET method of a URL. See: What is the character limit on URL

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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