none
A cross-platform serialization scenario RRS feed

  • Question

  • Hello folks!

    I am working on the project below:
    ----------------------------------------------------------------------------------------------------
    A cross-platform serialization scenario.
    Which could be used in WPF, Xamarin and all mobile phones, asp.net core and ...
    This will be cross platform file format for a total package.
    Be fast in speed ( tens of thousands of records could be in a file )

    Methods in each sample (the usage):
    1. Serializing
    2. De-serializing
    ----------------------------------------------------------------------------------------------------

    Any advise on how to achieve my goals would be welcome.
    Saturday, April 1, 2017 6:42 PM

Answers

  • Hi hokushin,

    >>A cross-platform serialization scenario. Which could be used in WPF, Xamarin and all mobile phones, asp.net core and ...

    You could use JSON exchanging data in WPF, Xamarin and all mobile phones, asp.net core.

    >>1. Serializing 2. De-serializing

    You could use Newtonsoft Serializing and De-serializing. Here is a sample for your reference.

    http://www.newtonsoft.com/json/help/html/SerializingJSON.htm

    #Deserializing

    Product product = new Product();
     product.Name = "Apple";
     product.ExpiryDate = new DateTime(2008, 12, 28);
     product.Price = 3.99M;
     product.Sizes = new string[] { "Small", "Medium", "Large" };
    
     string output = JsonConvert.SerializeObject(product);
     //{
    //  "Name": "Apple",
    //  "ExpiryDate": "2008-12-28T00:00:00",
    //  "Price": 3.99,
    //  "Sizes": [
    //    "Small",
    //    "Medium",
    //    "Large"
    //  ]
    //}
    
    Product deserializedProduct = JsonConvert.DeserializeObject<Product>(output);

    #Serializing

    Product product = new Product();
     product.ExpiryDate = new DateTime(2008, 12, 28);
     
     JsonSerializer serializer = new JsonSerializer();
     serializer.Converters.Add(new JavaScriptDateTimeConverter());
     serializer.NullValueHandling = NullValueHandling.Ignore;
     
     using (StreamWriter sw = new StreamWriter(@"c:\json.txt"))
     using (JsonWriter writer = new JsonTextWriter(sw))
    {
        serializer.Serialize(writer, product);
        // {"ExpiryDate":new Date(1230375600000),"Price":0}
    }

    Best regards,

    Cole Wu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by hokushin Tuesday, April 4, 2017 7:57 AM
    Tuesday, April 4, 2017 2:16 AM
    Moderator