为什么在媒体类型中是 `text/html` 而是 `application/json`?

Why is it `text/html` but `application/json` in media types?

applicationtext 在媒体类型上有什么区别,它们什么时候使用什么?

例如有 text/html 但另一方面它是 application/json。

这是历史事件吗?

这在 mozilla 文档的 MIME types 页面上有描述。

application 指的是任何类型的二进制数据,而 text 理论上是人类可读的。

type/subtype

The structure of a MIME type is very simple; it consists of a type and a subtype, two strings, separated by a '/'. No space is allowed. The type represents the category and can be a discrete or a multipart type. The subtype is specific to each type.

A MIME type is case-insensitive but traditionally is written all in lower case.

在页面的下方,您可以找到包含离散类型的 table:

Type          Description
text          Represents any document that contains text and is theoretically human readable
image         Represents any kind of images. Videos are not included, though animated images (like animated gif) are described with an image type.
audio         Represents any kind of audio files
video         Represents any kind of video files
application   Represents any kind of binary data.

回答您关于 JSON 的问题,虽然您会经常遇到 JSON 人类可读的内容,但它主要用于包含数据,并不一定是为了简单地阅读。同时,机器总是可以轻松地将数据从 JSON 转换为对象(假设 JSON 格式正确)。