5

My problem is that I can't read my json file that I'm creating in c#. I need my longitude and latitude values in my js. I need these for creating a google maps webview. My js can't find/read this file. I'm not sure if this is the correct way of reading/making the json file.

With this I create my JSON file. The beginPositie has 2 variables: longitude and latitude.

 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(); } } } 

This is my function for reading the JSON file in JS. The "Windows" can't be found and I don't know the reason for that. I have already included the scripts, installed the extension SDK for js but for a reason I can't add the reference to this 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); } }); 

}

1 Answer 1

2

Check out the localFolder property of the ApplicationData class. This code should retrieve the file data you're looking for:

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 }); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.