Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
356 views
in Technique[技术] by (71.8m points)

json - 什么是正确的JSON内容类型?(What is the correct JSON content type?)

I've been messing around with JSON for some time, just pushing it out as text and it hasn't hurt anybody (that I know of), but I'd like to start doing things properly.

(我一直在弄乱JSON一段时间,只是将其作为文本推出,并没有伤害任何人(据我所知),但是我想正确地做事。)

I have seen so many purported "standards" for the JSON content type:

(我见过这么多的所谓的“标准”为JSON内容类型:)

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

But which one is correct, or best?

(但是哪一个是正确的,还是最好的?)

I gather that there are security and browser support issues varying between them.

(我发现在它们之间存在安全性和浏览器支持问题。)

I know there's a similar question, What MIME type if JSON is being returned by a REST API?

(我知道有一个类似的问题, 如果REST API返回JSON,则为哪种MIME类型?)

, but I'd like a slightly more targeted answer.

(,但我想要一个更有针对性的答案。)

  ask by Oli translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

For JSON text:

(对于JSON文本:)

application/json

The MIME media type for JSON text is application/json .

(JSON文本的MIME媒体类型为application/json 。)

The default encoding is UTF-8.

(默认编码为UTF-8。)

(Source: RFC 4627 ).

((来源: RFC 4627 )。)

For JSONP (runnable javascript) with callback:

(对于带回调的JSONP (可运行的javascript):)

application/javascript

Here are some blog posts that were mentioned in the comments that are relevant.

(这是相关评论中提到的一些博客文章。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.8k users

...