日期:2014-05-17  浏览次数:20715 次

SpringMVC 前台往后台传JSON解析问题
我有一个JSON如下:
{
    "topicquestion": [
        {
            "topicquestion": "1"
        }
    ],
    "secquestion": [
        {
            "secquestion": ""
        }
    ],
    "thrquestion": [
        {
            "thrnextquestion": "dasdasd",
            "aoption": "",
            "boption": "",
            "coption": "",
            "doption": "",
            "answer": "1"
        }
    ]
}
请问用SpringMVC后台如何接

------解决方案--------------------
spring 自动封装了往前台传 JSON。往后台的话可以这样试试
  @RequestMapping(value = "/login", method = RequestMethod.POST,headers={"Accept=*/*","content-type=application/json"})
    @ResponseBody
    public MySubscriber getSubscriber(@RequestBody MyAuthentication myAuthentication) {
        LOGGER.log(Level.INFO, "getSubscriber");

        System.out.println("getSubscriber method : "+myAuthentication);


        MySubscriber mySubscriber = helloWebService.getSubscriber(myAuthentication);
        LOGGER.log(Level.INFO, "mySubscriber : " + mySubscriber);
        System.out.println( "mySubscriber : " + mySubscriber);
        return mySubscriber;
    }