locked
read a local json file in javascript

    Question

  • Hello! I have a navigation app and I want to read a json file and to put it on one of the pages out. Here is my code:

    (function () {
        "use strict";
    
        WinJS.UI.Pages.define("/pages/someFolder/somePage.html", {
            ready: function (element, options) {
            },
          
            readJson: function() {
                var packageFolder = Windows.ApplicationModel.Package.current.installedLocation;
                packageFolder.createFolderAsync("folderWithJson", Windows.Storage.CreationCollisionOption.openIfExists).then(
                    function (appDataFolder) {
                        appDataFolder.createFileAsync("myJson.json", Windows.Storage.CreationCollisionOption.openIfExists).then(
                            function (file) {
                                Windows.Storage.FileIO.readTextAsync(file).done(
                                    function (contents) {
                                        console.log(contents);
                                        var myJson = JSON.parse(contents);
                                        document.getElementById("someElement").innerHTML = myJson;
                                    },
                                    function (error) {
                                        console.log(error);
                                    });
                            },
                            function (error) {
                                console.log(error);
                            });
                    },
                    function (error) {
                        console.log(error);
                    });
            },
           
            unload: function () {...

    What am I doing wrong? I don't even get a console output.

    Best regards!

    Thursday, July 04, 2013 10:12 AM

Answers

All replies