JSON

Spring MVC ѧϰ±Ê¼Ç11

×ÖºÅ+ ×÷ÕߣºH5Ö®¼Ò À´Ô´£ºH5Ö®¼Ò 2016-03-07 16:01 ÎÒÒªÆÀÂÛ( )

Spring MVC ѧϰ±Ê¼Ç11 ¡ª¡ª ºó¶Ë·µ»Øjson¸ñʽÊý¾Ý Spring MVC ѧϰ±Ê¼Ç11 -- ºó¶Ë·µ»Øjson¸ñʽÊý¾Ý ÎÒÃdz£³£Ìý˵jsonÊý¾Ý,Ê×ÏÈ,ʲôÊÇjsonÊý¾Ý,×ܽáÆðÀ´,ÓÐÒÔÏÂ

Spring MVC ѧϰ±Ê¼Ç11 ¡ª¡ª ºó¶Ë·µ»Øjson¸ñʽÊý¾Ý

Spring MVC ѧϰ±Ê¼Ç11 ¡ª¡ª ºó¶Ë·µ»Øjson格ʽÊý¾Ý  ÎÒÃdz£³£Ìý˵jsonÊý¾Ý£¬Ê×ÏÈ£¬Ê²Ã´ÊÇjsonÊý¾Ý£¬×ܽáÆðÀ´£¬ÓÐÒÔϼ¸µã£º

   1. JSONµÄÈ«³ÆÊÇ¡±JavaScript Object Notation¡±£¬Òâ˼ÊÇJavaScript¶ÔÏó±íʾ·¨.
   2. ËüÊÇÒ»ÖÖ»ùÓÚÎı¾£¬¶ÀÁ¢ÓÚÓïÑÔµÄÇáÁ¿¼¶Êý¾Ý½»»»格ʽ.
   3. jsonµÄÁ½Öֽṹ£º¶ÔÏó{key:value,key:value,...}  ºÍ  Êý×é [value, value2, ... ]
   4. json×Ö·û´®£ºÆÕͨ×Ö·û´®¡¢json×Ö·û´®¡¢json¶ÔÏóµÄÇø±ð
   5. ²»Í¬±à³Ì¹¤¾ßʹÓÃjsonµÄ·½·¨

 ²Î¿¼£º


Spring MVC ·µ»ØjsonÊý¾Ý£¬ÓÃshowÀ´ÊµÏÖ£º

UserController.java:

±£³ÖÁ½Ì×ÇëÇó£¬Ò»Ì×ÊÇ´«Í³µÄÇëÇó·µ»ØÊý¾Ý£»Ò»Ì×ÊÇÇëÇójson格ʽ·µ»ØÊý¾Ý¡£

//6. ²éÒ»¸öÓû§ show.jsp @RequestMapping(value="/{username}", method=RequestMethod.GET) public String show(@PathVariable String username, Model model){ model.addAttribute("user1",users.get(username)); //user1²ÎÊýÊôÐÔÃû£¬µ½ÁËÊÓͼ£¬¾ÍÊÇuser1 return "user/show"; } //6. ²éÒ»¸öÓû§ show.jsp @RequestMapping(value="/{username}", method=RequestMethod.GET, params="jsoon") @ResponseBody //ÕâÀïÒª¼ÓÒ»ÐÐ public User show(@PathVariable String username){ //ÉùÃ÷ÖÐûÓÐÁËModel //model.addAttribute("user1",users.get(username)); return users.get(username); //²»·µ»ØStringÁË£¬·µ»Øuser¶ÔÏó }
˵Ã÷£¬ÒÔÉÏ´úÂëÖУº

  1. [email protected], 
  2. no return String, but User Object
  3. no Model
  4. directly return users.get(username)//×¢Òâ·µ»ØµÄÊÇÒ»¸öUser¶ÔÏó
  5. ¿ÉÒÔÔÚRequestMappingÐÐÔö¼ÓÒ»¸öÇëÇó值£ºParams="jsoon"//ÕâÊǹ涨ÈçÒª½øÕâ¸ö·½·¨·µ»Øjson£¬ÐèÒª´ø¸ö²ÎÊýjsoon

´Ëʱ¿É²âÊÔ£¬·µ»Ø406´íÎóÈçͼ£º£¨Í¨¹ýurl¼ÓÈë?jsoon·ÃÎÊÁË£¬µ«Ã»ÓÐÍ·ÎļþΪËü½øÐнâÊÍ£©

Spring MVC ѧϰ±Ê¼Ç11 —— ºó¶Ë·µ»Øjson¸ñʽÊý¾Ý



ËùÒÔÎÒÃÇÐèÒª¼ÓÈëÒ»¸öjar°ü£ºjackson-all-1.x.x.jar

´ÓÕâ¸öÍøÖ·¿ÉÒÔÏÂÔص½£º

°Ñjar°üµ½ÏîÄ¿Îļþ¼Ð/libÎļþ¼ÐÏ£¬ÖØÐÂdebug£¬Á´½Ó½øÈ룺:8080/myhello/user/sdy?jsoon

´Ëʱ£¬ÓеÄä¯ÀÀÆ÷Chrome£¬firefoxµÈÄÜÏÔʾÈçÏ£¬ÆäËûä¯ÀÀÆ÷Èç360µÈ£¬»áÌáʾÏÂÔØsdy.jsonÎļþ£¬notepad++´ò¿ªÒÔºóÒ²ÊÇÈçÏÂÄÚÈÝ¡£

Spring MVC ѧϰ±Ê¼Ç11 —— ºó¶Ë·µ»Øjson¸ñʽÊý¾Ý



Enjoy ;)









¸ü¶àÏà¹ØÎÄÕÂ

  • 
ASP.NET MVCÉÏ´«Îļþ³É¹¦·µ»ØJson¸ñʽÊý¾Ýµ¯³öÏÂÔØ¿ò½â¾ö·½°¸

    ASP.NET MVCÉÏ´«Îļþ³É¹¦·µ»ØJson¸ñʽÊý¾Ýµ¯³öÏÂÔØ¿ò½â¾ö·½°¸

    ×î½ü×öÒ»¸öÏîÄ¿,ÉÏ´«ÎļþºóÎÒ·µ»ØÒ»¸öJson¸ñʽµÄÊý¾Ý,ÌáʾÉÏ´«³É¹¦,¿ÉÊÇÀϵ¯³öÏÂÔØ¿òÈçÏ ºÜÓôÃÆ,ÍøÉÏÕÒÁ˺ܶà×ÊÁÏ,¶¼²»ÀíÏë,ÄÉÃÆÐí¾Ã,ÖÕÓÚÓÐÁ˽â¾ö·½°¸.ºǫ́ÉÏ´«³É¹¦ºóÊÇÕâôдµÄ:return Json("{msg:'ÉÏ´«³É¹¦'}");ǰ̨ÊÇÕâô½ÓµÄvar json = eva ...

  • Springѧϰ±Ê¼ÇMVC3.1SpringMVC·µ»ØJsonÊý¾Ý·½Ê½1À©Õ¹

    Springѧϰ±Ê¼ÇMVC3.1SpringMVC·µ»ØJsonÊý¾Ý·½Ê½1À©Õ¹

    <Springѧϰ±Ê¼Ç-MVC>ϵÁÐÎÄÕÂ,½²½â·µ»ØjsonÊý¾ÝµÄÎÄÕ¹²ÓÐ3ƪ,·Ö±ðΪ:[Springѧϰ±Ê¼Ç-MVC-3]SpringMVC·µ»ØJsonÊý¾Ý-·½Ê½1:[Springѧϰ±Ê¼Ç-M ...

  • Spring MVC ѧϰ±Ê¼Ç json¸ñʽµÄÊäÈëºÍÊä³ö

    Spring MVC ѧϰ±Ê¼Ç json¸ñʽµÄÊäÈëºÍÊä³ö

    ±¾ÎÄת×Ô²©¿ÍÔ°,×÷Õß:Öֲ˵ùÏ,ʱ¼ä:2015-4-2 Spring mvc´¦ÀíjsonÐèҪʹÓÃjacksonµÄÀà¿â,Òò´ËΪ֧³Öjson¸ñʽµÄÊäÈëÊä³öÐèÒªÏÈÐÞ¸Äpom.xmlÔö¼Ójackson°üµÄÒýÓà <!-- json --> <dependency> <groupI ...

  • Spring MVC ѧϰ±Ê¼Ç6 —— ʵÏÖ¼òµ¥µÄÓû§¹ÜÀí2Ìí¼ÓºÍÑéÖ¤

    Spring MVC ѧϰ±Ê¼Ç6 -- ʵÏÖ¼òµ¥µÄÓû§¹ÜÀí(2)¶Ôuser modelµÄÔöɾ¸Ä²é Ôö¼ÓÓû§: 1. ¶¥¼¶Ò³ÃæÇëÇóдÔÚclassÍ·Àï ÔÚ"UserController.java"ÎļþÖÐ:¶¥¼¶Ò³ÃæÇëÇóÊÇ/user, ¹Ê RequestMapping("/us ...

  • Spring MVC ѧϰ±Ê¼Ç12 —— SpringMVC+Hibernate¿ª·¢1ÒÀÀµ°ü´î½¨

    Spring MVC ѧϰ±Ê¼Ç12 —— SpringMVC+Hibernate¿ª·¢1ÒÀÀµ°ü´î½¨

    ¡¡

  • 1.±¾Õ¾×ñÑ­ÐÐÒµ¹æ·¶£¬ÈκÎתÔصĸå¼þ¶¼»áÃ÷È·±ê×¢×÷ÕߺÍÀ´Ô´£»2.±¾Õ¾µÄÔ­´´ÎÄÕ£¬ÇëתÔØʱÎñ±Ø×¢Ã÷ÎÄÕÂ×÷ÕߺÍÀ´Ô´£¬²»×ðÖØÔ­´´µÄÐÐΪÎÒÃǽ«×·¾¿ÔðÈΣ»3.×÷ÕßͶ¸å¿ÉÄܻᾭÎÒÃDZ༭Ð޸Ļò²¹³ä¡£

    Ïà¹ØÎÄÕÂ
    • ¼øÓÚCXF¿ò¼ÜµÄwebserviceѧϰ ´«µÝxml,json²¢½âÎö

      ¼øÓÚCXF¿ò¼ÜµÄwebserviceѧϰ ´«µÝxml,json²¢½âÎö

      2016-03-07 17:00

    • IOSѧϰ±Ê¼Ç£¨16£©ÍøÂçÇëÇó£¬json½âÎö

      IOSѧϰ±Ê¼Ç£¨16£©ÍøÂçÇëÇó£¬json½âÎö

      2016-03-01 17:00

    • Json.Netѧϰ±Ê¼Ç(Ê®¶þ) ЭÒé½âÎö

      Json.Netѧϰ±Ê¼Ç(Ê®¶þ) ЭÒé½âÎö

      2016-03-01 16:00

    •  JSONÈëÃż¶Ñ§Ï°×ܽá-JSONÊý¾Ý½á¹¹

      JSONÈëÃż¶Ñ§Ï°×ܽá-JSONÊý¾Ý½á¹¹

      2016-02-25 11:05

    ÍøÓѵãÆÀ
    ²