我需要在Web服务调用中将一些值从移动设备传递到服务器,因此我计划将JSON格式的所有值传递如下
{ "nameservice": [ { "id": 7413, "name": "ask" }, { "id": 7414, "name": "josn" }, { "id": 7415, "name": "john" }, { "id": 7418, "name": "R&R" } ] }
以下是我的服务电话
@RequestMapping("/saveName") @ResponseBody public String saveName(String acc) {jsonObject = new JSONObject(); try { ); System.out.println(acc); jsonObject.accumulate("result", "saved "); } catch(Exception e) { e.printStackTrace();jsonObject.accumulate("result", "Error Occured "); } return jsonObject.toString(); }
我正在尝试通过这种方式致电上述服务
localhost:8080/service/saveName?acc={ "nameservice": [ { "id": 7413, "name": "ask" }, { "id": 7414, "name": "josn" }, { "id": 7415, "name": "john" }, { "id": 7418, "name": "R&R" } ] }
但是输出是这样的
{ "nameservice": [ { "id": 7413, "name": "ask" }, { "id": 7414, "name": "josn" }, { "id": 7415, "name": "john" }, { "id": 7418, "name": "R
谁能告诉我为什么我不能获得所有的价值观?
我建议将JSON数据作为POST请求传递给主体。但是,如果你仍然希望将其作为URL中的参数传递,则必须像下面这样对URL进行编码,例如:
对于前json是:->{"name":"ABC","id":"1"}
->{"name":"ABC","id":"1"}
testurl:80/service?data=%7B%22name%22%3A%22ABC%22%2C%22id%22%3A%221%22%7D