views:

54

answers:

1

Hello

Is there any way to have Json.net serialize an object directly to a NetworkStream?

In other words, have Json.net send the serialized result to the network as it serializes the object (in a streaming fashion).

I would like to avoid having to serialize the object to memory and then send it via the NetworkStream.

Any thoughts?

Regards

+1  A: 

You can create a TextWriter on top of a NetworkStream, and serialize to the TextWriter; or you can create a JsonTextWriter on top of a TextWriter and serialize to that.

You don't need to serialize to, say, a temporary string or byte array first.

Tim Robinson