通过TVJS-tvOS消费API JSon调用

use*_*649 6 javascript api xcode node.js tvos

我正在尝试使用tvOS,我对处理json调用有一个小问题.我必须通过API获取一些数据,让我们说为了测试我正在调用此链接

http://query.yahooapis.com/v1/public/yql?q=select%20item%20from%20weather.forecast%20where%20location%3D%223015%22&format=json
Run Code Online (Sandbox Code Playgroud)

我尝试使用此功能进行一些修改

function getDocument(url) {
  var templateXHR = new XMLHttpRequest();
  templateXHR.responseType = "json";
  templateXHR.open("GET", url, true);
  templateXHR.send();
  return templateXHR;
}
Run Code Online (Sandbox Code Playgroud)

但没有成功.任何提示或帮助?

如果我需要使用NodeJS,我该怎么办?

Ale*_*ley 1

您是否在“App.onLaunch”中调用了您的函数

App.onLaunch = function(options) {
  var url = 'http://query.yahooapis.com/v1/public/yql?q=select%20item%20from%20weather.forecast%20where%20location%3D%223015%22&format=json';
  var doc = getDocument(url);
  console.log(doc);
}
Run Code Online (Sandbox Code Playgroud)

可能值得一看https://mathiasbynens.be/notes/xhr-responsetype-json