application/json
application/x-javascript
text/javascript
text/x-javascript
text/x-json
我用哪一种,在哪里?我假设安全和浏览器支持问题是一个因素。
application/json
application/x-javascript
text/javascript
text/x-javascript
text/x-json
我用哪一种,在哪里?我假设安全和浏览器支持问题是一个因素。
当前回答
我用下面的用法
contentType: 'application/json',
data: JSON.stringify(SendData),
其他回答
当然,对JSON来说正确的MIME媒体类型是application/json
,但有必要了解在您的应用程序中预期会收到何种类型的数据。
例如,我使用Ext GWT 离 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");
}
});
使用申请/日文响应类型,浏览器建议我保存文件。
服务器侧端源代码片断使用春春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);
}
};
如果从JSON的REST API获得数据,必须使用内容类型:
缩略
application/json
PHP 中保存数组或对象数据的工作非常出色 。
我用这个代码把数据输入JSONGoogle Cloud 储存(GCS)设定了可公开观看:
$context = stream_context_create([
'gs' => [
'acl'=>'public-read',
'Content-Type' => 'application/json',
]
]);
file_put_contents(
"gs://BUCKETNAME/FILENAME.json",
json_encode((object) $array),
false,
$context
);
要返回数据是直线前进的:
$data = json_decode(file_get_contents("gs://BUCKETNAME/FILENAME.json"));
为补充先前的答复,JSON 链接数据的MIME类型(JSON-LD)以 W3C 计算是:
application/ld+json
类型名称 :应用
子类型名称 :Ld+json 键盘
此外,来自同一来源的:
文件扩展名:
.jsonld