从URL函数-NativeScript获取JSON

从URL函数-NativeScript获取JSON,json,nativescript,Json,Nativescript,如何编写http模块函数从本地json文件读取数据?我现在用这个来读取数据。我想让函数从这个url读取数据- 要从Android emulator访问localhost,请参阅 简而言之-http://10.0.2.2:替换本地主机: 有关发出http请求的信息,请参阅http上的。要访问您的,应如下所示: http.getJSON("http://10.0.2.2:8000/source.json").then(function (r) { //// Argument (r) is J

如何编写http模块函数从本地json文件读取数据?我现在用这个来读取数据。我想让函数从这个url读取数据-


要从Android emulator访问localhost,请参阅

简而言之-
http://10.0.2.2:
替换
本地主机:

有关发出http请求的信息,请参阅http上的。要访问您的,应如下所示:

http.getJSON("http://10.0.2.2:8000/source.json").then(function (r) {
    //// Argument (r) is JSON!
}, function (e) {
    //// Argument (e) is Error!
    //console.log(e);
});

最后,如果您需要从应用程序目录中读取JSON,一个
require
就足够了。

要从Android emulator访问localhost,请参阅

简而言之-
http://10.0.2.2:
替换
本地主机:

有关发出http请求的信息,请参阅http上的。要访问您的,应如下所示:

http.getJSON("http://10.0.2.2:8000/source.json").then(function (r) {
    //// Argument (r) is JSON!
}, function (e) {
    //// Argument (e) is Error!
    //console.log(e);
});

最后,如果您需要从应用程序目录中读取JSON,一个
require
就足够了。

好的!这就是您编写它的方式-viewModel.set(“categoricalSource”,source.categoricalSource);-在它说//参数(r)是JSON的地方!好吧这就是您编写它的方式-viewModel.set(“categoricalSource”,source.categoricalSource);-在它说//参数(r)是JSON的地方!