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

后端 未结 6 645
庸人自扰
庸人自扰 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: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.

提交回复
热议问题