如何在服务器中使用jackson解析json对象

时间:2014-12-03 12:59:42

标签: java json parsing jackson

我使用ajax帖子将用户名,密码,邮件和电话发送到服务器。我想解析服务器中发送的json数据。我该怎么做?

var usname=
$(document).ready(function()
{
   $("#signup").click(function()
    {
          $.ajax(
          {
          type: 'POST',
          url: '/signup',
          dataType: 'json',
          data: {
                    uname: document.getElementById("usname").value,
                    pword: document.getElementById("psword").value,
                    mail: document.getElementById("mail").value,
                    phone: document.getElementById("phone").value    
                },    
                success: function (data) {    
                    window.location.href="/";
                },
                error: function(){
                    window.location.href="/";   
                }

            });

      });
});

Java代码:

 @RequestMapping(value="/signup",method=RequestMethod.POST)
  public String signupUser(@RequestParam String uname, @RequestParam String pword,@RequestParam S         
  String mail, @RequestParam String phone,HttpServletRequest request, HttpServletResponse   
   response,HttpSession session) throws MailException 
{
    DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();

    Entity uDetails = new Entity("UDetails");

    uDetails.setProperty("userName",uname);
    uDetails.setProperty("passWord", pword);
    uDetails.setProperty("email",mail);
    uDetails.setProperty("phoneNumber",phone);

    datastore.put(uDetails);

    System.out.println("I got printed");

    session.setAttribute("username", uname);
    session.setAttribute("loggedin","yes");

    System.out.println("I got printed too ");
    return "redirect:/";

}

当然,我可以通过请求参数注释来做到这一点。但是,我已经获得了一项任务,其中我被特别要求使用jackson解析json对象

0 个答案:

没有答案