0

我正在开发 Windows 8 App,我的目标是从数据库中创建一个带有名称和适当位置的 json 文件。最后,我使用该 json 文件链接到 Telerik 图表并填充数据。

在下面的代码片段中,“GetAutomationPageStaticGroups”是我的控制器中的一个函数,它将检索 json 文件。

function createJsonFile() {
        WinJS.xhr({
            url: apiUrl + "GetAutomationPageStaticGroups"
        })
};

我的查询是如何修改上面的代码片段以在应用程序内的适当位置存储具有适当名称的 json 文件?

4

1 回答 1

0

assuming that WinJS.xhr code that you have shared is working - following code can be used to save it to a file as 'data.json' under application local data.

var storage = Windows.Storage;
var data;
WinJS.xhr(({
        url: apiUrl + "GetAutomationPageStaticGroups"
    }).then(function oncomplete(req)
    {
        data = req.responseText;
        return storage.ApplicationData.current.localFolder.createFileAsync(
                        'data.json',
                        storage.CreationCollisionOption.replaceExisting);
    }.then(function oncreatecomplete(file)
    {
         return storage.FileIO.writeTextAsync(file, data,
                storage.Streams.UnicodeEncoding.utf8);
    }).then(null, function onerror(error)
    {
        // TODO: handle error here
    });
于 2013-06-22T03:49:00.823 回答