Advertisement
wackloner

Untitled

May 30th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.74 KB | None | 0 0
  1. string jsonFileName = "history.json";
  2. ObservableCollection<HistoryEntry> entries;
  3. var serializer = new DataContractJsonSerializer(typeof(ObservableCollection<HistoryEntry>));
  4. using (var stream = await ApplicationData.Current.LocalFolder.OpenStreamForWriteAsync(
  5.                 jsonFileName, CreationCollisionOption.ReplaceExisting)) {
  6.     serializer.WriteObject(stream, entries);
  7. }
  8. string jsonContext;
  9. var myStream = await ApplicationData.Current.LocalFolder.OpenStreamForReadAsync(jsonFileName);
  10. using (var reader = new StreamReader(myStream)) {
  11.     jsonContent = await reader.ReadToEndAsync();
  12. }
  13. using (var ms = new MemoryStream(Encoding.Unicode.GetBytes(jsonContent))) {
  14.     Entries = serializer.ReadObject(ms) as ObservableCollection<HistoryEntry>;
  15. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement