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 内容-类型:申请/xml 内容-类型:文本/html
其他回答
NANA将JSON的正式MIME类型登记为申请/json。
当被问及为什么不是文本/json时,Crockford似乎说JSON其实不是JSON的JavaScript,也不是文本,而且IANA比文本/*更可能发出申请/*。
更多资源:
媒体类型 要求征求第4627条评论:JSON有一个类型
“申请/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())
}
}
我用下面的用法
contentType: 'application/json',
data: JSON.stringify(SendData),
您可能需要更经常地使用这些内容, 尽量记住这三种内容类型, 尽管有许多内容类型 :
内容-类型:申请/json 内容-类型:申请/xml 内容-类型:文本/html
当然,对 JSON 来说正确的 MIME 媒体类型是应用程序/json, 但有必要了解在您的应用程序中需要什么样的数据。
例如,我使用Ext GWT, 服务器响应必须作为文本/ html, 但包含 JSON 数据 。
客户端, Ext GWT 窗体收听器
uploadForm.getForm().addListener(new FormListenerAdapter()
{
@Override
public void onActionFailed(Form form, int httpStatus, String responseText)
{
MessageBox.alert("Error");
}
@Override
public void onActionComplete(Form form, int httpStatus, String responseText)
{
MessageBox.alert("Success");
}
});
如果使用应用程序/json回应类型,浏览器建议我保存文件。
使用 Spring MVC 的服务器侧端源代码代码片断
return new AbstractUrlBasedView()
{
@SuppressWarnings("unchecked")
@Override
protected void renderMergedOutputModel(Map model, HttpServletRequest request,
HttpServletResponse response) throws Exception
{
response.setContentType("text/html");
response.getWriter().write(json);
}
};