4 回答

TA貢獻(xiàn)1757條經(jīng)驗(yàn) 獲得超8個(gè)贊
對(duì)于JSON文本:
application/json
JSON文本的MIME媒體類型是
application/json
。默認(rèn)編碼為UTF-8。(來源:RFC 4627)。
對(duì)于帶回調(diào)的JSONP(可運(yùn)行的javascript):
application/javascript
以下是相關(guān)評(píng)論中提到的一些博客文章。
IANA的官方mime類型列表來自@ gnrfan的答案如下


TA貢獻(xiàn)1802條經(jīng)驗(yàn) 獲得超6個(gè)贊

TA貢獻(xiàn)1946條經(jīng)驗(yàn) 獲得超4個(gè)贊
當(dāng)然,JSON的正確MIME媒體類型是application/json
,但有必要實(shí)現(xiàn)應(yīng)用程序中預(yù)期的數(shù)據(jù)類型。
例如,我使用Ext GWT,服務(wù)器響應(yīng)必須為text / html,但包含JSON數(shù)據(jù)。
客戶端,Ext GWT表單監(jiān)聽器
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"); }});
如果使用application / json響應(yīng)類型,瀏覽器建議我保存文件。
使用Spring MVC的服務(wù)器端源代碼片段
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); }};
- 4 回答
- 0 關(guān)注
- 1139 瀏覽
添加回答
舉報(bào)