0

At the moment, I've got a JSON file with content looking like this:

{
"username": "test", 
"someNumber": 100
}  

I'm using JSON.Net to fetch the .JSON file from a webserver - C#:

        var http = new HttpClient();
        http.MaxResponseContentBufferSize = Int32.MaxValue;
        var response = await http.GetStringAsync(URI);

        var result = JsonConvert.DeserializeObject<DatClass.Result>(response);

This works great together with the class getting/setting the properties. However, what I would like to know is whether there's a good way for a user to update the .JSON file through a textbox UI? As in:

[textbox - update username] [update button] -> username sent to server -> .JSON file updated -> [textblock - showing updated username in UI].

I'm not looking for exact code solutions, I'm rather looking for good solutions on this, and/or if this is a terrible idea of an easy database(?).

2
  • serialize updated object and overwrite the file Commented Nov 13, 2012 at 23:13
  • Well, is this even a good way of storing information? It seems like it's not much documentation related to actually using JSON as a "database" which is able to be updated very much. Been looking at Azure databases as well, but it seems like most devs refrain from using it in their apps since Metro apps shouldn't have direct DB connection..(?) Commented Nov 14, 2012 at 8:19

1 Answer 1

1

Ok. Now I get it :)

So you want to have a DB. Then read this. 3 methods

  1. Your way. You want to use JSON files. Ok it will work but it's a bad way imo. if you'll have 1 MB file (it's not so big) than every time you'll have to read it, deserialize, update data, serialize and write it again. It isn't a good way.

  2. SQLite. If you want a local database use SQLite. I'm in phase of testing it and it looks good. A disadvantage is poor orm. You need to manage few things by yourself but it work nice. This is a local database so it's not a bad way to go

  3. Azure DB. Main disadvantage is that you app is depended on internet connection and you need to create an API that will provide connection with the DB cause Windows Store Apps can't connect to them by themself. You need also consider creating cache engine cause asking for thata every time is pointless. you can get data and cache them for some views. that way app will work faster

// EDIT

in your updated case you have 2 solutions

  1. Use SQLite as a smaller local cache for the data from web. It will make your app more independent from internet connection
  2. Just go for internet dependend app

In all of this cases you need a db in web and some api to connect with it

Sign up to request clarification or add additional context in comments.

4 Comments

1. Yeah, I thought about that as well. Especially when the file gets bigger, and it requires data connection to fetch the JSON, it could become an expensive app to use. 2. I've looked at SQLite - what do you think so far? And would one be able to sync this (the DB file) to a server? I want the app to be sync-able between Windows 8 and Windows Phone, so that settings and more is saved in the database, then fetched onto the platform being used. 3. I think I'd go for SQLite then :)!
@AndrewB exactly. I suggest SQLite if you want to have local db or Azure DB If the cost and needing of internet connection isn't problem for you
Ah, updating the previous post didn't work out too well here! :: I've looked at SQLite - what do you think so far? And would one be able to sync this (the DB file) to a server? I want the app to be sync-able between Windows 8 and Windows Phone, so that settings and more is saved in the database, then fetched onto the platform being used.
Thanks! I think I'll try SQLite more before deciding on this. Having SQLite caching the info would have been a huge plus, so I might just go for that solution. It's a bit sad, seeing as JSON was such an easy technology to work with in Windows Store apps, but SQLite can't be that much worse... or? :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.