使用 Json.net 将 .net 对象直接序列化为 NetworkStream

发布于 2024-09-10 19:25:25 字数 175 浏览 1 评论 0原文

有没有办法让 Json.net 将对象直接序列化到 NetworkStream?

换句话说,让 Json.net 在序列化对象时将序列化结果发送到网络(以流式传输方式)。

我想避免必须将对象序列化到内存,然后通过 NetworkStream 发送它。

有什么想法吗?

问候

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

撩动你心 2024-09-17 19:25:26

您可以在 NetworkStream 之上创建一个 TextWriter,并序列化到 TextWriter;或者您可以在 TextWriter 之上创建一个 JsonTextWriter 并序列化到它。

您不需要首先序列化为临时字符串或字节数组。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文