Tuesday, 15 September 2015

c# - Serialize a custom List to JSON and deserialize the same to that custom list using Newtonsoft -


In my Windows 8.1 app, I want to store the results of my custom generated list better for my local storage so that I can retrieve the app after the closure can be later later.
The NewtonSoft JSON Serializer helps me sort my list into string format that I can store in a text file. But deserializing it will not be used to bring the necessary list

class

  public class BookDetailsItem {public string id {get; Set; } Public ImageSource CoverImage {Get; Set; } Public string name {get; Set; } Public Visibility Progressive {Receiving; Set; } Public listing & lt; StoryDetailsItem & gt; Stories (get; set;}} public class StoryDetailsItem {public string id {get; set;} public string name {get; set;} public ImageSource CoverImage {get; set;} public string time {receive; set;} Public string word {get} set;} public visibility progressee {receive; set;}}  

Now I am adding my essential items to this category list

  list & lt; BookDetailsItem & gt; Tempbook = new list & lt; BookDetailsIte M & gt; (); tempbook.Add (......);  

Now serializing it I can store it in any txt file

 string tempstr = JsonConvert.SerializeObject (tempbook);  

But deserializing this how I can get back the same list I am receiving is an object that is not in the correct format

  var obj1 = (JsonConvert. DeserializeObject (tempstr));  

Is there any other way in which I can access these data in local storage more easily And better way to create a SQLite database Nothing) can be stored.

use

  var obj1 = JsonConvert.DeserializeObject & lt ; List & amp;; BookDetailsItem & gt; & Gt; (Tempstr)  

Deserializer type information to give.


No comments:

Post a Comment