Reading and writing JSON

UWPTest
Brian Lima 8 years ago
parent 03b7fff6ce
commit 1c52ba21ad

Binary file not shown.

@ -18,7 +18,10 @@ namespace UWPHook
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 @@ namespace UWPHook
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…
Cancel
Save