有没有现成的,现有的JSON序列化帮手.NET基础类库类? [英] Is there Any Off-The-Shelf Json Serialization helper class in .NET BCL?

查看:193
本文介绍了有没有现成的,现有的JSON序列化帮手.NET基础类库类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要序列化/从字符串反序列化一些对象为/,转让刚才不透明的数据。我可以用XmlSerializer的做,但生成的字符串看起来笨拙而长。那么,有没有简明的序列化提供.NET?

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 long. So, is there any concise Serializer available in .NET?

第一件事来我想到的是,也许是.NET应该有JSON序列化,但我不能找到它。有没有现成的现成办法在.NET中对象转换为/从简洁的字符串?

The first thing coming to my mind is that perhaps .NET should have JSON Serializer, but I cannot find it. Is there any off-the-shelf approach in .NET to convert object to/from concise string?

推荐答案

有两种;

  • <一个href="http://msdn.microsoft.com/en-us/library/system.runtime.serialization.json.datacontractjsonserializer.aspx">DataContractJsonSerializer 3.5
  • <一个href="http://msdn.microsoft.com/en-us/library/system.web.script.serialization.javascriptserializer.aspx">JavaScriptSerializer在3.5 SP1
  • DataContractJsonSerializer in 3.5
  • JavaScriptSerializer in 3.5 SP1

在传统的方式,它们是相互,其他不是100%兼容,尤其是重的DateTime ; DCJS用途(IIRC)一个文本字符串; JSS使用 - 既不可以正确读取t'other

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.

当然,如果文本,如果不透明,你也可以使用任何简明的二进制序列,并简单地基地-64连接code它;例如, protobuf网是pretty的简洁。但是,使用JSON最大限度地减少所需的各端的外部code,那么很可能是你最好的选择。

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.

这篇关于有没有现成的,现有的JSON序列化帮手.NET基础类库类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆