JSON 内容类型有许多“标准 ” :
application/json
application/x-javascript
text/javascript
text/x-javascript
text/x-json
我用哪一种,在哪里?我假设安全和浏览器支持问题是一个因素。
相关:如果JSON被REST API送回,什么MIME类型?
JSON 内容类型有许多“标准 ” :
application/json
application/x-javascript
text/javascript
text/x-javascript
text/x-json
我用哪一种,在哪里?我假设安全和浏览器支持问题是一个因素。
相关:如果JSON被REST API送回,什么MIME类型?
当前回答
内容-类型:应用/json - JSON 内容-类型:应用/javascript-内容-类型:应用/x-javascript 内容-类型:应用/x-javascript - 内容-类型: JavaScript 内容-类型:文本/jawaScript :文本/javascript 但应用/json 正式注册前 JSON - JSON
其他回答
如果您使用 Ubuntu 或 Debian , 并通过 Apache 服务于 .json 文件, 您可能需要以正确的内容类型服务文件 。 我这样做主要是因为我想使用 Firefox 扩展 JSONView
Apache 模块 mod_ mime 将有助于轻松做到这一点。 但是, 您需要编辑文件/ etc/ mime. type 并添加行
application/json json
然后重新启动 Apache :
sudo service apache2 restart
“申请/json”是JSON正确的内容类型。
def ajaxFindSystems = {
def result = Systems.list()
render(contentType:'application/json') {
results {
result.each{sys->
system(id:sys.id, name:sys.name)
}
}
resultset (rows:result.size())
}
}
为了补充先前的答复,根据W3C,JSON链接数据(JSON-LD)的MIME类型是:
应用程序/ld+json 类型名称: 应用程序 子类型名称: ld+json
此外,来自同一来源的:
文件扩展名:.jsonld
在 JSP 中,您可以在页面指令中使用此指令 :
<%@ page language="java" contentType="application/json; charset=UTF-8"
pageEncoding="UTF-8"%>
JSON的正确MIME媒体类型是申请/json, JSP将用来向客户发送回复。
JSON 文本:
application/json
JSON 文本的 MIME 媒体类型是应用程序/ json。 默认编码是 UTF-8 。 (资料来源: RFC 4627)
JSONP (可运行的 JavaScript) 使用回调 :
application/javascript
以下是相关评论中提到的一些博客文章:
JSON Internet Explorer 为何不使用文本/ html 用于 JSON 的 JSON Internet Explorer 有时与应用程序/ json 有问题,