基本json格式,java代码获取  如以下post请求参数

       

java post带json请求参数 java接收post请求json串_json

 

1. 请求方式

 @RequestMapping(value="test",method=RequestMethod.POST)

2.获取方式  

2.1  JSONObject

public void   test  (@RequestBody JSONObject ,jsonObject) {

       //获取test1
        String test1= jsonObject.getString("test1");

        //获取test2
        String test2= jsonObject.getString("test2");

        System.out.print("test1:"+test1+";test2"+test2);

}

 

结果: test1:old;  test2:new ;

2.  HttpServletRequest

public void   springUpload(HttpServletRequest request) {

        //获取test1
        String test1= request.getParameter("test1");

        //获取test2
        String test2= request.getParameter("test2");

        System.out.print("test1:"+test1+";test2"+test2);

}

结果: test1:old;  test2:new ;

3.String 

 

public void   uploadWccXml(@RequestBody String xmlstr) {

        //对象转化
        JSONObject jsonObject = JSONObject.parseObject(param);

         //获取test1

        String test1= jsonObject.getString("test1");

        //获取test2
        String test2= jsonObject.getString("test2");

}