从本地Windows应用商店文件夹中读取js中的文件

use*_*561 5 javascript json winjs windows-store-apps

我的问题是我无法读取我在c#中创建的json文件.我需要在我的js中使用经度和纬度值.我需要这些来创建谷歌地图webview.我的js无法找到/读取此文件.我不确定这是否是读取/制作json文件的正确方法.

有了这个我创建我的JSON文件.beginPositie有2个变量:经度和纬度.

        public async Task Serialize(Coordinate beginPositie)
        {
        string json = JsonConvert.SerializeObject(beginPositie);

        StorageFolder localFolder = ApplicationData.Current.LocalFolder;

        StorageFile MarkersFile = await localFolder.CreateFileAsync("markers.json", CreationCollisionOption.ReplaceExisting);

        using (IRandomAccessStream textStream = await MarkersFile.OpenAsync(FileAccessMode.ReadWrite))
        {
            using (DataWriter textWriter = new DataWriter(textStream))
            {
                textWriter.WriteString(json);
                await textWriter.StoreAsync();
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

这是我在JS中读取JSON文件的函数.无法找到"Windows",我不知道原因.我已经包含了脚本,为js安装了扩展SDK,但由于某种原因我无法添加对此SDK的引用.

function getJSON() {
//var uri = new Windows.Foundation.Uri('ms-appdata:///local/markers.json');
//json = Windows.Storage.StorageFile.getFileFromApplicationUriAsync(uri);
$.ajax({
    url: "ms-appdata:///local/markers.json",
    success: function (data) {
        json = JSON.parse(data);
    }
});
Run Code Online (Sandbox Code Playgroud)

}

Ste*_*ner 2

查看该类的localFolderApplicationData属性。此代码应该检索您正在查找的文件数据:

Windows.Storage.ApplicationData.current.localFolder.getFileAsync("markers.json").done(
 function (file) {
    Windows.Storage.FileIO.readTextAsync(file).done(
       function (fileContent) {
          //'fileContent' contains your JSON data as a string
       },
       function (error) {
          //file couldn't be read - handle the error
       });
 },
 function (error) {
    //file not found, handle the error
 });
Run Code Online (Sandbox Code Playgroud)