如今作的一個項目是作app服務端的,須要從app接收json的請求數據,服務端框架用的是SpringMVC,因此天然而然的想到直接用@RequestBody來接收json數據,java
格式以下:ajax
public ResponseProtocolMap login(@RequestBody JSONObject requestJson,HttpServletRequest request) { ResponseProtocolMap responseProtocolMap = null; //中間內容省略。。。 return responseProtocolMap; }
剛開始導入的是org.json.jar的org.json.JSONObject的包,請求的時候,出現了415錯誤:json
HTTP Status 415 - type Status report message description The server refused this request because the request entity is in a format not supported by the requested resource for the requested method. Apache Tomcat/7.0.64
在這個問題上找了好久解決方法,都沒有找到,原本還覺得SpringMVC不支持直接接收json呢,後來將json包換成了net.sf.json-lib.jar的net.sf.json.JSONObject就解決問題了app
注:測試了用ajax直接傳json數據仍是會出現415錯誤,若是直接用http請求post提交json的數據流,測試是正常的,不懂若是是用ajax請求要怎麼接收,知道的朋友麻煩幫忙說下,謝謝。框架