Git Product home page Git Product logo

Comments (3)

mbencho avatar mbencho commented on June 16, 2024

Hi I was wondering if this would be applicable to ImportJSON as well? Is there any reason I couldn't use it there? I'm not that familiar with where this piece of code should be inserted in the larger code. Thanks for your help

from importjson.

mbencho avatar mbencho commented on June 16, 2024

So I got this to work - but only if I hard code the var object length.

http://live.nhle.com/GameData/20132014/2013020758/gc/gcbx.jsonp

Using this with 6989 hardcoded it imports the data. I don't know enough code to know why "content.length" doesn't work

function ImportJSONAdvanced(url, fetchOptions, query, parseOptions, includeFunc, transformFunc) {
var jsondata = UrlFetchApp.fetch(url, fetchOptions);
var content = jsondata.getContentText();
var ignoreStart = 10;
var ignoreEnd = 1;
var object = JSON.parse(content.substring(ignoreStart, 6989-ignoreEnd));

return parseJSONObject_(object, query, parseOptions, includeFunc, transformFunc);
}

from importjson.

yppo avatar yppo commented on June 16, 2024

I think this can be handled like this.

function ImportJSONAdvanced(url, fetchOptions, query, parseOptions, includeFunc, transformFunc) {
  var jsondata = UrlFetchApp.fetch(url, fetchOptions);
  
  try {
    var object   = JSON.parse(jsondata.getContentText());
    return parseJSONObject_(object, query, parseOptions, includeFunc, transformFunc);
  }
  catch(err) {
    var object   = jsondata.getContentText();
    var firstBr = object.indexOf("[") > object.indexOf("{") ? object.indexOf("{") : object.indexOf("[");
    var lastBr = object.lastIndexOf(")");
    var newObject=  JSON.parse(object.substring(firstBr, lastBr));
    return parseJSONObject_(newObject, query, parseOptions, includeFunc, transformFunc);
    
  }
}

from importjson.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.