mirror of
https://github.com/BrianLima/UWPHook.git
synced 2024-11-12 01:10:26 +00:00
Reading and writing JSON
This commit is contained in:
parent
03b7fff6ce
commit
1c52ba21ad
Binary file not shown.
@ -18,7 +18,10 @@ public class GameModel
|
||||
public GameModel()
|
||||
{
|
||||
games = new ObservableCollection<Game>();
|
||||
var y = JsonConvert.DeserializeObject<GameModel>("games.json");
|
||||
using (StreamReader read = new StreamReader("games.json"))
|
||||
{
|
||||
games = JsonConvert.DeserializeObject<ObservableCollection<Game>>(read.ReadToEnd());
|
||||
}
|
||||
}
|
||||
|
||||
private ObservableCollection<Game> _games;
|
||||
@ -37,8 +40,10 @@ public void Add(Game game)
|
||||
public void Store()
|
||||
{
|
||||
JsonSerializer serializer = new JsonSerializer();
|
||||
using (StreamWriter sw = new StreamWriter(@"games.json")) {
|
||||
using (JsonWriter writer = new JsonTextWriter(sw)){
|
||||
using (StreamWriter sw = new StreamWriter(@"games.json"))
|
||||
{
|
||||
using (JsonWriter writer = new JsonTextWriter(sw))
|
||||
{
|
||||
serializer.Serialize(writer, _games);
|
||||
}
|
||||
}
|
||||
|
Binary file not shown.
Binary file not shown.
@ -1,15 +1 @@
|
||||
[
|
||||
|
||||
{
|
||||
"game_alias": "teste",
|
||||
"game_path": "teste"
|
||||
},
|
||||
{
|
||||
"game_alias": "teste",
|
||||
"game_path": "teste"
|
||||
},
|
||||
{
|
||||
"game_alias": "teste",
|
||||
"game_path": "teste"
|
||||
}
|
||||
]
|
||||
[{"game_alias":"teste","game_path":"teste"},{"game_alias":"teste","game_path":"teste"},{"game_alias":"teste","game_path":"teste"},{"game_alias":"teste","game_path":"teste"},{"game_alias":"teste","game_path":"teste"}]
|
@ -1,3 +1 @@
|
||||
{
|
||||
|
||||
}
|
||||
[{"game_alias":"teste","game_path":"teste"},{"game_alias":"teste","game_path":"teste"},{"game_alias":"teste","game_path":"teste"},{"game_alias":"teste","game_path":"teste"},{"game_alias":"teste","game_path":"teste"}]
|
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user