如今作的一个项目是作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请求要怎么接收,知道的朋友麻烦帮忙说下,谢谢。框架