我的问题是,我无法读取我正在c#中创建的json文件。我需要js中的经度和纬度值。我需要这些来创建一个谷歌地图网页。我的js找不到/读不到这个文件。我不确定这是否是读取/制作json文件的正确方式。
这样我就创建了我的JSON文件。beginPositie有两个变量:经度和纬度。
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);
}
});}
发布于 2013-11-26 15:44:00
查看localFolder类的ApplicationData属性。此代码应该检索您要查找的文件数据:
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
});https://stackoverflow.com/questions/20163777
复制相似问题