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"));
作为一些研究,
最常见的MIME类型是
申请/日文
让我们举个例子来区分杰森和爪哇史克里普特
当不知道该数据将如何使用时,即使用该数据。当信息仅以 JSON 格式从服务器中提取时,它可以通过链接或任何文件(如果是的话)来使用。
比如说...
<?php
header('Content-type:application/json');
$directory = [
['Id' => 1, 'Name' => 'this'],
['Id' => 2, 'Name' => 'is'],
['Id' => 3, 'Name' => 'Stack Overflow'],
];
// Showing the JSON data
echo json_encode($directory);
?>
产出是,
[{"Id":1, "Name":"this"}, {"Id":2, "Name":"is"}, {"Id":3, "Name":"Stack Overflow"}]
在预先定义数据使用时使用该数据,在客户端 Ajax 应用程序调用时使用该数据,在JSON-P型或JSON-P型数据时使用该数据。贾索普.
例如,例如
<?php
header('Content-type:application/javascript');
$dir = [
['Id' => 1, 'Name' => 'this' ],
['Id' => 2, 'Name' => 'is'],
['Id' => 3, 'Name' => 'Stack Overflow'],
];
echo "Function_call(" . json_encode($dir) . ");";
?>
产出是,
Function_call([{"Id":1, "Name":"this"}, {"Id":2, "Name":"is"}, {"Id":3, "Name":"Stack Overflow"}])
关于其他MIME类型,请参看MIME类型(亚马尼亚州媒体类型).
“application/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())
}
}