我应该在 JSON 中还是在单独的二进制连接中移动大数据 blob?

发布于 2024-08-28 08:00:04 字数 640 浏览 3 评论 0原文

问题:

为了简单起见,使用 JSON 发送大型数据 blob 更好,还是通过单独的连接将它们作为二进制数据发送更好?

如果是前者,您能否提供有关如何优化 JSON 以最小化大小的提示?

如果是后者,是否值得使用出现在两​​者中的标识符将 JSON 数据逻辑连接到二进制数据,例如“data”:“<唯一标识符>”在 JSON 中,数据 blob 的第一个字节 <唯一标识符> ?

上下文:

我的 iPhone 应用程序需要通过 3G 网络接收 JSON 数据。这意味着我需要认真考虑数据传输的效率以及CPU的负载。

大多数数据传输都是相对较小的文本数据包,JSON 是其自然格式,因此无需过多担心效率。

然而,一些最关键的传输将是大块二进制数据——肯定至少有 100 KB 的数据,并且随着客户使用该产品的历史积累得更久,可能会接近 1 MB。 (注意:我将在 iPhone 本身上缓存尽可能多的内容,但数据仍然必须至少传输一次。)它不是流数据。

我可能会使用第三方 JSON SDK - 我在开发过程中使用的 SDK 位于 此处.

谢谢

QUESTION:

Is it better to send large data blobs in JSON for simplicity, or send them as binary data over a separate connection?

If the former, can you offer tips on how to optimize the JSON to minimize size?

If the latter, is it worth it to logically connect the JSON data to the binary data using an identifier that appears in both, e.g., as "data" : "< unique identifier >" in the JSON and with the first bytes of the data blob being < unique identifier > ?

CONTEXT:

My iPhone application needs to receive JSON data over the 3G network. This means that I need to think seriously about efficiency of data transfer, as well as the load on the CPU.

Most of the data transfers will be relatively small packets of text data for which JSON is a natural format and for which there is no point in worrying much about efficiency.

However, some of the most critical transfers will be big blobs of binary data -- definitely at least 100 kilobytes of data, and possibly closer to 1 megabyte as customers accumulate a longer history with the product. (Note: I will be caching what I can on the iPhone itself, but the data still has to be transferred at least once.) It is NOT streaming data.

I will probably use a third-party JSON SDK -- the one I am using during development is here.

Thanks

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

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

发布评论

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

评论(1

意中人 2024-09-04 08:00:04

您可以尝试在发送之前压缩 JSON(可能是 gz),然后在客户端解压缩。

但我不确定这会如何影响 iPhone 的性能。

You could try to compress the JSON (gz perhaps) before you send it and then uncompress it on the client-side.

But I'm not sure how that affects iPhone performance.

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