0

I'd like to load this JSON into a variable: http://itunes.apple.com/lookup?id=327630330

Is there a fast and quick method that does not require external libraries?

Jonny
  • 15,955
  • 18
  • 111
  • 232

2 Answers2

3

It looks like the service supports JSONP, so you just have to define a function and include a script tag pointing to the service:

<script>
function iTunesData(data) {
    // do something with data
}
</script>
<script src="http://itunes.apple.com/lookup?id=327630330&callback=iTunesData"></script>

Assuming of course you are running the code on the browser. You can also create the script element dynamically.

Community
  • 1
  • 1
Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143
0

My environment is Google Spreadsheets. I found out how to do it for this environment:

var result = UrlFetchApp.fetch("http://someurl/mydata.json");
var o  = Utilities.jsonParse(result.getContentText());

Reference here: https://developers.google.com/apps-script/reference/url-fetch/url-fetch-app

And FWIW I ended up writing this custom function to fetch title of an item (app, song etc) from iTunes by Apple ID. You can use it in Google Spreadsheets:

function jghgTitleForAppleid(appleid) {
  var theid = appleid;
  var completeurl = 'http://itunes.apple.com/lookup?&id=' + theid;

  response = UrlFetchApp.fetch(completeurl);
  var o = Utilities.jsonParse(response.getContentText());
  var title = o["results"][0]["trackName"]

  return title;
}
Jonny
  • 15,955
  • 18
  • 111
  • 232