Solved

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

Posted on 2016-08-14
3
61 Views
Last Modified: 2016-08-15
Hello,

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)
            {                
                newdata.data[j].volume[0] = exdata.vol;        //This is just for testing. The indexes of volume, last, low and high
                newdata.data[j].last[0] = exdata.last;              //require to be edited with conditions.
                newdata.data[j].low[0] = exdata.low;          
                newdata.data[j].high[0] = exdata.high;
               
                i++;
            }

            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",
  "data":
  [
    {
      "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.
0
Comment
Question by:Soumen Roy
  • 2
3 Comments
 
LVL 51

Accepted Solution

by:
Julian Hansen earned 500 total points
ID: 41755969
This looks like a permissions problem. Check the permissions of your folder you are trying to write to.
0
 

Author Closing Comment

by:Soumen Roy
ID: 41756416
Thanks, it worked :-)
0
 
LVL 51

Expert Comment

by:Julian Hansen
ID: 41756479
You are welcome.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
"In order to have an organized way for empathy mapping, we rely on a psychological model and trying to model it in a simple way, so we will split the board to three section for each persona and a scenario and try to see what those personas would Do,…
This video teaches users how to migrate an existing Wordpress website to a new domain.
The viewer will learn how to dynamically set the form action using jQuery.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now