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
我用哪一种,在哪里?我假设安全和浏览器支持问题是一个因素。
当前回答
缩略
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"));
其他回答
如果您使用 Ubuntu 或 Debian 或 Debian , 通过 Apache 服务于 .json 文件, 您可能需要以正确内容类型服务文件。 我这样做主要是因为我想使用 Firefox 扩展名Json View 吉森(Jsson View )
Apache 模块调制(_mime)将会帮助您轻松完成此操作 。 但是, 您需要用 Ubuntu 来编辑文件/eec/mime.类型添加一行
application/json json
然后重新启动 Apache :
sudo service apache2 restart
IANA 亚非那JSON 正式注册的 MIME 类型为 JSONapplication/json
.
当被问及为何不问时text/json
Crockford似乎已经说Jsonon其实不是 JavaScript 或文本,application/*
大于text/*
.
更多资源:
当然,对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);
}
};