有许多“标准”为“标准”Json Json (Json Json) (Json Json Json) (Json Json) Json Json (Json Json) Json (Json) Json (Json) Json (Json) Json (Json) Json (Json) Json (Json) Json(Json) Json (Json) Json (Json) Json(Json) Json (Json) Json内容类型 :

application/json
application/x-javascript
text/javascript
text/x-javascript
text/x-json

我用哪一种,在哪里?我假设安全和浏览器支持问题是一个因素。

相关:如果JSON被AST API送回来 是什么MIME类型?


当前回答

  • Content-Type: application/json-杰森
  • Content-Type: application/javascript - 杰森-普
  • Content-Type: application/x-javascript - JavaScript
  • Content-Type: text/javascript - JavaScript 但是,但用于 HTML 属性的旧的因特网探索者版本。
  • Content-Type: text/x-javascript- JavaScript媒体类型,但是,但过时
  • Content-Type: text/x-json- 曾经杰森申请/日文正式注册。

其他回答

我用下面的用法

contentType: 'application/json',
data: JSON.stringify(SendData),

JSON 的正确内容类型是application/json除非你们在使用贾索普,也称为 Json with Padding, 实际上是 JavaScript, 所以正确的内容类型将是application/javascript.

IANA 亚非那JSON 正式注册的 MIME 类型为 JSONapplication/json.

当被问及为何不问时text/jsonCrockford似乎已经说Jsonon其实不是 JavaScript 或文本,application/*大于text/*.

更多资源:

缩略application/jsonPHP 中保存数组或对象数据的工作非常出色 。

我用这个代码把数据输入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"));

给杰森:

Content-Type: application/json

用于杰森-普:

Content-Type: application/javascript