5
我的問題是我無法讀取我在c#中創建的json文件。我需要我的經度和緯度值在我的js。我需要這些創建谷歌地圖webview。我的js無法找到/讀取此文件。我不確定這是否是讀取/製作json文件的正確方法。從本地窗口存儲文件夾中讀取js文件
用這個我創建我的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();
}
}
}
這是我閱讀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);
}
});
}