How to use JSON file as data storage in Universal Windows 10 App?


I am a newbie in working with JSON files. I am developing a Universal Windows 10 application that calls data from various APIs and displays them in a list. The data needs to be stored in a JSON file and then be displayed from the file. Each time the application is run, the API data is to be called and compared with the data that is present in the storage file to check whether the values are going up or down, and then overwrite parts of the JSON file with new data.

I have written a code and it is reading the data from the JSON file. However, the part for writing the data to the file is not working. When the application is run, it is shutting down with the following error "Access to the path 'F:\Shared\Development\BitcoinExchangeApp\BitcoinExchangeApp\bin\x86\Debug\AppX\ExchangeData.json' is denied."

Relevant part of my code is given below:
newdata = olddata;                                                             //olddata is the object which reads data from JSON file

            int j = 0;                                                                     //newdata is the object which is to be written to the JSON file

            foreach(var exdata in DatafromAPI)
      [j].volume[0] = exdata.vol;        //This is just for testing. The indexes of volume, last, low and high
      [j].last[0] = exdata.last;              //require to be edited with conditions.
      [j].low[0] = exdata.low;          
      [j].high[0] = exdata.high;

            File.WriteAllText(@"ExchangeData.json", JsonConvert.SerializeObject(newdata));
            using (StreamWriter file = File.CreateText(@"ExchangeData.json"))
                JsonSerializer serializer = new JsonSerializer();
                serializer.Serialize(file, newdata);
Here is the part of the JSON file that I created:
  "file": "exdata",
      "exname": "CEX.IO",
      "currencies": [ "LTC", "USD", "EUR", "ETH" ],
      "volume": [ "0.0", "0.0", "0.0", "0.0" ],
      "last": [ "0.0", "0.0", "0.0", "0.0" ],
      "low": [ "0.0", "0.0", "0.0", "0.0" ],
      "high": [ "0.0", "0.0", "0.0", "0.0" ]
      "exname": "OKCoin",
      "currencies": [ "LTC", "USD" ],
      "volume": [ "0.0", "0.0" ],
And here are the classes for de/serializing the JSON:
public class DetailsforExchange
        public string exname { get; set; }
        public List<string> currencies { get; set; }
        public List<string> volume { get; set; }
        public List<string> last { get; set; }
        public List<string> low { get; set; }
        public List<string> high { get; set; }

    public class DatabaseofExchanges
        public string file { get; set; }
        public List<DetailsforExchange> data { get; set; }

Help is much needed.

Thanks and regards.
Soumen RoySenior ManagerAsked:
Who is Participating?
Julian HansenConnect With a Mentor Commented:
This looks like a permissions problem. Check the permissions of your folder you are trying to write to.
Soumen RoySenior ManagerAuthor Commented:
Thanks, it worked :-)
Julian HansenCommented:
You are welcome.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.