有许多“标准”为“标准”Json Json (Json Json) (Json Json Json) (Json Json) Json Json (Json Json) Json (Json) Json (Json) Json (Json) Json (Json) Json (Json) Json (Json) Json(Json) Json (Json) Json (Json) Json(Json) Json (Json) Json内容类型 :

application/json
application/x-javascript
text/javascript
text/x-javascript
text/x-json

我用哪一种,在哪里?我假设安全和浏览器支持问题是一个因素。

相关:如果JSON被AST API送回来 是什么MIME类型?


当前回答

如果您在客户端环境中, 调查交叉浏览器支持是强制的, 对于一个支持良好的网络应用程序来说 。

正确的 HTTP 内容类型application/json,正如其他人也已经强调过, 但有些客户对它处理得不好, 这就是为什么jQuery建议默认text/html.

其他回答

如果您使用 Ubuntu 或 Debian 或 Debian , 通过 Apache 服务于 .json 文件, 您可能需要以正确内容类型服务文件。 我这样做主要是因为我想使用 Firefox 扩展名Json View 吉森(Jsson View )

Apache 模块调制(_mime)将会帮助您轻松完成此操作 。 但是, 您需要用 Ubuntu 来编辑文件/eec/mime.类型添加一行

application/json json

然后重新启动 Apache :

sudo service apache2 restart

正如许多其他人已经提到的那样,application/json是正确答案。

但还没有被解释的是你提出的其他选择 意指什么

  • application/x-javascript: JavaScript 以前 JavaScript 的实验 MIME 类型application/javascript成为标准。

  • text/javascript:现在过时。你应该使用application/javascript当使用 Javaramps 时。

  • text/x-javascript:上述情况下的实验性MIME类型。

  • text/x-jsonJSON 之前的实验 MIME 类型application/json正式注册。

总的来说,当你对内容类型有任何疑问时,你应该检查此链接

这取决于观点。

如果您是寄件请求的客户端,application/json是正确的选择。

但如果您是收到请求的服务器, 您必须做好准备, 客户端也可以发送编码 。 因此, 请准备 。application/jsonapplication/json; charset=utf-8有效。

两种情况下媒体类型相同。 但内容类型不同 。

  • Content-Type: application/json-杰森
  • Content-Type: application/javascript - 杰森-普
  • Content-Type: application/x-javascript - JavaScript
  • Content-Type: text/javascript - JavaScript 但是,但用于 HTML 属性的旧的因特网探索者版本。
  • Content-Type: text/x-javascript- JavaScript媒体类型,但是,但过时
  • Content-Type: text/x-json- 曾经杰森申请/日文正式注册。

并非所有内容都适合内容类型application/json.

如果您正在使用Ext JS向上传文件提交窗窗窗后,请注意服务器响应由浏览器解析,以创建文档<iframe>.

如果服务器正在使用 JSson 发送返回对象, 那么Content-Type必须设置为text/html以便告诉浏览器将未改变的文字插入文档正文。

见见Ext JS 3.4.0 API文件.