Introduction

This blog is mainly focused on SharePoint
I will use this to store and share all the tips and tricks about SharePoint and the related products
List of all posts

Building and saving JSON Object to file in METRO Application


Topic Building and saving JSON Object to file in METRO Application
OutputThe dedicated functions

Step Description
1 Create the jason object
function TestJson() {
    Windows.Storage.ApplicationData.current.localFolder.createFileAsync("sample.json", Windows.Storage.CreationCollisionOption.openIfExists).done(
        Windows.Storage.ApplicationData.current.localFolder.getFileAsync("sample.json").done(
            function (fjson) {
                var oJSON = {};
                oJSON.oTraining = {};
                oJSON.oTraining.Id = "1";
                for (var i = 0; i < 6; i++) {
                    oJSON.Sessions[i] = {};
                    oJSON.Sessions[i].Id = i;
                }
                // sub arrays
                oJSON.Sessions[5] = {};
                oJSON.Sessions[5].Id = i;
                oJSON.Sessions[5].oFract = new Array();
                oJSON.Sessions[5].oFract[0] ={};
                oJSON.Sessions[5].oFract[0].Id = 1;
                oJSON.Sessions[5].oFract[1] ={};
                oJSON.Sessions[5].oFract[1].Id = 2;
                oJSON.Sessions[5].oFract[2] ={};
                oJSON.Sessions[5].oFract[2].Id = 3;
                Windows.Storage.FileIO.writeTextAsync(fjson, JSON.stringify(oJSON));
            }
        )
    )
}
 

No comments:

Post a Comment

by Category