开发者

JSON.NET & controlling the type information provided in the output stream

We are looking to use JSON.NET.net on a cross platform solution.

Given the structure of the data we are passing around, we need to include the type details with the information that is serialized.

We can get the type information into the stream by using the TypeNameHandling property of JsonSerializer, but we end up with a lot more information being sent over the wire.

What we would like to do is do something similar to开发者_Python百科 what the MS JavaScriptSerializer does i.e. provider a JavaScriptTypeResolver which we then replace out long type names with something a lot shorter.

Is this possible to achieve with JSON.NET?


I think you should take a look at JSON.NET "Contract Resolvers". I quote:

The IContractResolver interface provides a way to customize how the JsonSerializer serializes and deserializes .NET objects to JSON.

Implementing the IContractResolver interface and then assigning an instance to a JsonSerializer lets you control whether the object is serialized as a JSON object or JSON array, what object members should be serialized, how they are serialized and what they are called.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜