Is there Any Off-The-Shelf Json Serialization helper class in .NET BCL?

后端 未结 6 628
庸人自扰
庸人自扰 2020-12-17 10:22

I need to serialize/de-serialize some objects into/from string and transfer them as just opaque data. I can use XmlSerializer to do it, but generated string looks clumsy and

相关标签:
6条回答
  • 2020-12-17 10:49

    I have a very fast open source JsonSerializer available that can serialize any POCO or DataContract type, including Interfaces anonymous and late bound types, etc.

    Basic Example

    var customer = new Customer { Name="Joe Bloggs", Age=31 };
    var json = JsonSerializer.SerializeToString(customer);
    var fromJson = JsonSerializer.DeserializeFromString<Customer>(json); 
    
    0 讨论(0)
  • 2020-12-17 10:54

    JsonFx.NET has an open-source serializer which allows serialization to/from strongly typed classes which might be what you're looking for. You can control how dates are serialized and override many aspects of the serialization. It even interacts well with Linq by supporting serialization of anonymous objects. The API works just like .NET XML serialization.

    0 讨论(0)
  • 2020-12-17 10:56

    Json.Net is a JSON library for .NET. It is available in CodePlex.

    0 讨论(0)
  • 2020-12-17 10:58

    just use your own api.. its easy to create json.. but you can also use JSON libraries like JSON.NET..

    happy coding

    0 讨论(0)
  • 2020-12-17 10:59

    There are two;

    • DataContractJsonSerializer in 3.5
    • JavaScriptSerializer in 3.5 SP1

    In the traditional way, they aren't 100% compatible with each-other, especially re DateTime; DCJS uses (IIRC) a literal string; JSS uses new - and neither can read t'other correctly.

    Of course, if the text if opaque, you could also use any concise binary serializer, and simply base-64 encode it; for example, protobuf-net is pretty terse. But using JSON minimizes the external code needed at each end, so may well be your best bet.

    0 讨论(0)
  • LINQ To Json can serialize and deserialize.

    0 讨论(0)
提交回复
热议问题