Èç¹ûÄúÔĶÁÁ˱¾ÏµÁÐÇ°ÃæµÄÎÄÕ£¬ÄÇôӦÒѶÔÊý¾Ý¸ñʽÓÐÁËÏ൱µÄÈÏʶ¡£Ç°ÃæµÄÎÄÕ½âÊÍÁËÔÚÐí¶àÒì²½Ó¦ÓóÌÐòÖÐÈçºÎÇ¡µ±µØʹÓô¿Îı¾ºÍ¼òµ¥µÄÃû³Æ / Öµ¶Ô¡£¿ÉÒÔ½«Êý¾Ý×éºÏ³ÉÏÂÃæÕâÑùµÄÐÎʽ£º
firstName=Brett&lastName=McLaughlin&email=brett@newInstance.com
ÕâÑù¾ÍÐÐÁË£¬²»ÐèÒªÔÙ×öʲôÁË¡£Êµ¼ÊÉÏ£¬Web ÀÏÊÖ»áÒâʶµ½Í¨¹ý GET ÇëÇó·¢Ë͵ÄÐÅÏ¢¾ÍÊDzÉÓÃÕâÖÖ¸ñʽ¡£
È»ºó£¬±¾ÏµÁÐÌÖÂÛÁË XML¡£ÏÔÈ»£¬XML µÃµ½ÁËÏ൱¶àµÄ¹Ø×¢£¨ÕýÃæºÍ¸ºÃæµÄÆÀ¼Û¶¼ÓУ©£¬ÒѾÔÚ Ajax Ó¦ÓóÌÐòÖй㷺ʹÓ᣹ØÓÚÈçºÎʹÓà XML Êý¾Ý¸ñʽ£¬¿ÉÒÔ»Ø¹Ë ±¾ÏµÁÐÇ°ÃæµÄÎÄÕ£º
<request> <firstName>Brett</firstName> <lastName>McLaughlin</lastName> <email>brett@newInstance.com</email> </request>
ÕâÀïµÄÊý¾ÝÓëÇ°Ãæ¿´µ½µÄÏàͬ£¬µ«ÊÇÕâÒ»´Î²ÉÓà XML ¸ñʽ¡£ÕâûʲôÁ˲»ÆðµÄ£»ÕâÖ»ÊÇÁíÒ»ÖÖÊý¾Ý¸ñʽ£¬Ê¹ÎÒÃÇÄܹ»Ê¹Óà XML ¶ø²»ÊÇ´¿Îı¾ºÍÃû³Æ / Öµ¶Ô¡£
±¾ÎÄÌÖÂÛÁíÒ»ÖÖÊý¾Ý¸ñʽ£¬JavaScript Object Notation£¨JSON£©¡£JSON ¿´ÆðÀ´¼ÈÊìϤÓÖÄ°Éú¡£ËüÌṩÁËÁíÒ»ÖÖÑ¡Ôñ£¬Ñ¡Ôñ·¶Î§¸ü´ó×ÜÊǺÃÊÂÇé¡£
Ñ¡ÔñµÄÒâÒåÔÚÉîÈëÑо¿ JSON ¸ñʽµÄϸ½Ú֮ǰ£¬ÄúÓ¦¸ÃÁ˽âΪʲôҪÓÃÁ½ÆªÎÄÕÂÌÖÂÛÁíÒ»ÖÖÊý¾Ý¸ñʽ£¨Êǵģ¬±¾ÏµÁÐÖеÄÏÂһƪÎÄÕÂÒ²ÌÖÂÛ JSON£©£¬ÓÈÆäÔÚÒѾÁ˽âÁËÈçºÎʹÓà XML ºÍ´¿Îı¾µÄÃû³Æ / Öµ¶ÔµÄÇé¿öÏ¡£Æäʵ£¬ÔÒòºÜ¼òµ¥£º½â¾öÈκÎÎÊÌâµÄÑ¡ÔñÔ½¶à£¬ÕÒµ½ÎÊÌâµÄ ×î¼Ñ½â¾ö·½°¸µÄ¿ÉÄÜÐÔ¾ÍÔ½´ó£¬Õâ±ÈÖ»ÄÜʹÓà һ¸ö½â¾ö·½°¸ÒªºÃµÃ¶à¡£
»Ø¹ËÃû³Æ / Öµ¶ÔºÍ XML±¾ÏµÁÐÒѾÓÃÁË´óÁ¿Æª·ùÌÖÂÛÊʺÏʹÓÃÃû³Æ / Öµ¶ÔºÍ XML µÄ³¡ºÏ¡£×ÜÊÇÓ¦¸ÃÊ×ÏÈ¿¼ÂÇʹÓÃÃû³Æ / Öµ¶Ô¡£¶ÔÓÚ´ó¶àÊýÒì²½Ó¦ÓóÌÐòÖеÄÎÊÌ⣬ʹÓÃÃû³Æ / Öµ¶Ô¼¸ºõ×ÜÊÇ×î¼òµ¥µÄ½â¾ö·½°¸£¬¶øÇÒËüÖ»ÐèÒª·Ç³£»ù±¾µÄ JavaScript ֪ʶ¡£
ʵ¼ÊÉÏ£¬³ý·ÇÓÐijÖÖÏÞÖÆÆÈʹÄúתÏò XML£¬·ñÔòÓò»×Å¿¼ÂÇʹÓñðµÄÊý¾Ý¸ñʽ¡£ÏÔÈ»£¬Èç¹ûÒªÏòÐèÒª XML ¸ñʽµÄÊäÈëµÄ·þÎñÆ÷¶Ë³ÌÐò·¢ËÍÊý¾Ý£¬ÄÇôϣÍûʹÓà XML ×÷ΪÊý¾Ý¸ñʽ¡£µ«ÊÇ£¬ÔÚ´ó¶àÊýÇé¿öÏ£¬¶ÔÓÚÐèÒªÏòÓ¦ÓóÌÐò·¢ËͶà¶ÎÐÅÏ¢µÄ·þÎñÆ÷£¬XML ÊǸüºÃµÄÑ¡Ôñ£»»»¾ä»°Ëµ£¬XML ͨ³£¸üÊʺÏÓÃÀ´ ÏòAjax Ó¦ÓóÌÐò×ö³öÏìÓ¦£¬¶ø²»ÊÇ ´ÓAjax Ó¦ÓóÌÐò·¢³öÇëÇó¡£
Ìí¼Ó JSONÔÚʹÓÃÃû³Æ / Öµ¶Ô»ò XML ʱ£¬Êµ¼ÊÉÏÊÇʹÓà JavaScript ´ÓÓ¦ÓóÌÐòÖÐÈ¡µÃÊý¾Ý²¢½«Êý¾Ýת»»³ÉÁíÒ»ÖÖÊý¾Ý¸ñʽ¡£ÔÚÕâЩÇé¿öÏ£¬JavaScript Ôںܴó³Ì¶ÈÉÏ×÷ΪһÖÖÊý¾Ý²Ù×ÝÓïÑÔ£¬ÓÃÀ´Òƶ¯ºÍ²Ù×ÝÀ´×Ô Web ±íµ¥µÄÊý¾Ý£¬²¢½«Êý¾Ýת»»ÎªÒ»ÖÖÊʺϷ¢Ë͸ø·þÎñÆ÷¶Ë³ÌÐòµÄ¸ñʽ¡£
µ«ÊÇ£¬ÓÐʱºò JavaScript ²»½ö½ö×÷Ϊ¸ñʽ»¯ÓïÑÔʹÓá£ÔÚÕâЩÇé¿öÏ£¬Êµ¼ÊÉÏʹÓà JavaScript ÓïÑÔÖеĶÔÏóÀ´±íʾÊý¾Ý£¬¶ø²»½öÊǽ«À´×Ô Web ±íµ¥µÄÊý¾Ý·Å½øÇëÇóÖС£ÔÚÕâЩÇé¿öÏ£¬´Ó JavaScript ¶ÔÏóÖÐÌáÈ¡Êý¾Ý£¬È»ºóÔÙ½«Êý¾Ý·Å½øÃû³Æ / Öµ¶Ô»ò XML£¬¾ÍÓеã¶ù ¶à´ËÒ»¾ÙÁË¡£Õâʱ¾ÍºÏÊÊʹÓà JSON£ºJSON ÔÊÐíÇáËɵؽ« JavaScript ¶ÔÏóת»»³É¿ÉÒÔËæÇëÇó·¢Ë͵ÄÊý¾Ý£¨Í¬²½»òÒì²½¶¼¿ÉÒÔ£©¡£
JSON ²¢²»ÊÇijÖÖħµ¯£»µ«ÊÇ£¬Ëü¶ÔÓÚijЩ·Ç³£ÌØÊâµÄÇé¿öÊǺܺõÄÑ¡Ôñ¡£²»ÒªÈÏΪÄú²»»áÓöµ½ÕâЩÇé¿ö¡£ÔĶÁ±¾ÎĺÍÏÂһƪÎÄÕÂÀ´Á˽â JSON£¬ÕâÑù£¬Óöµ½ÕâÀàÎÊÌâʱÄú¾ÍÖªµÀ¸ÃÔõô°ìÁË¡£
JSON »ù´¡¼òµ¥µØ˵£¬JSON ¿ÉÒÔ½« JavaScript ¶ÔÏóÖбíʾµÄÒ»×éÊý¾Ýת»»Îª×Ö·û´®£¬È»ºó¾Í¿ÉÒÔÔÚº¯ÊýÖ®¼äÇáËɵش«µÝÕâ¸ö×Ö·û´®£¬»òÕßÔÚÒì²½Ó¦ÓóÌÐòÖн«×Ö·û´®´Ó Web ¿Í»§»ú´«µÝ¸ø·þÎñÆ÷¶Ë³ÌÐò¡£Õâ¸ö×Ö·û´®¿´ÆðÀ´Óеã¶ù¹Å¹Ö£¨ÉÔºó»á¿´µ½¼¸¸öʾÀý£©£¬µ«ÊÇ JavaScript ºÜÈÝÒ×½âÊÍËü£¬¶øÇÒ JSON ¿ÉÒÔ±íʾ±ÈÃû³Æ / Öµ¶Ô¸ü¸´ÔӵĽṹ¡£ÀýÈ磬¿ÉÒÔ±íʾÊý×éºÍ¸´ÔӵĶÔÏ󣬶ø²»½ö½öÊǼüºÍÖµµÄ¼òµ¥ÁÐ±í¡£
¼òµ¥ JSON ʾÀý°´ÕÕ×î¼òµ¥µÄÐÎʽ£¬¿ÉÒÔÓÃÏÂÃæÕâÑùµÄ JSON ±íʾÃû³Æ / Öµ¶Ô£º
{ "firstName": "Brett" }
Õâ¸öʾÀý·Ç³£»ù±¾£¬¶øÇÒʵ¼ÊÉϱȵÈЧµÄ´¿Îı¾Ãû³Æ / Öµ¶ÔÕ¼Óøü¶àµÄ¿Õ¼ä£º
firstName=Brett
µ«ÊÇ£¬µ±½«¶à¸öÃû³Æ / Öµ¶Ô´®ÔÚÒ»Æðʱ£¬JSON ¾Í»áÌåÏÖ³öËüµÄ¼ÛÖµÁË¡£Ê×ÏÈ£¬¿ÉÒÔ´´½¨°üº¬¶à¸öÃû³Æ / Öµ¶ÔµÄ ¼Ç¼£¬±ÈÈ磺
{ "firstName": "Brett", "lastName":"McLaughlin", "email": "brett@newInstance.com" }
´ÓÓï·¨·½ÃæÀ´¿´£¬ÕâÓëÃû³Æ / Öµ¶ÔÏà±È²¢Ã»ÓкܴóµÄÓÅÊÆ£¬µ«ÊÇÔÚÕâÖÖÇé¿öÏ JSON ¸üÈÝÒ×ʹÓ㬶øÇҿɶÁÐÔ¸üºÃ¡£ÀýÈ磬ËüÃ÷È·µØ±íʾÒÔÉÏÈý¸öÖµ¶¼ÊÇͬһ¼Ç¼µÄÒ»²¿·Ö£»»¨À¨ºÅʹÕâЩֵÓÐÁËijÖÖÁªÏµ¡£
ÖµµÄÊý×éµ±ÐèÒª±íʾһ×éֵʱ£¬JSON ²»µ«Äܹ»Ìá¸ß¿É¶ÁÐÔ£¬¶øÇÒ¿ÉÒÔ¼õÉÙ¸´ÔÓÐÔ¡£ÀýÈ磬¼ÙÉèÄúÏ£Íû±íʾһ¸öÈËÃûÁÐ±í¡£ÔÚ XML ÖУ¬ÐèÒªÐí¶à¿ªÊ¼±ê¼ÇºÍ½áÊø±ê¼Ç£»Èç¹ûʹÓõäÐ͵ÄÃû³Æ / Öµ¶Ô£¨¾ÍÏñÔÚ±¾ÏµÁÐÇ°ÃæÎÄÕÂÖп´µ½µÄÄÇÖÖÃû³Æ / Öµ¶Ô£©£¬ÄÇô±ØÐ뽨Á¢Ò»ÖÖרÓеÄÊý¾Ý¸ñʽ£¬»òÕß½«¼üÃû³ÆÐÞ¸ÄΪ person1-firstNameÕâÑùµÄÐÎʽ¡£
Èç¹ûʹÓà JSON£¬¾ÍÖ»Ð轫¶à¸ö´ø»¨À¨ºÅµÄ¼Ç¼·Ö×éÔÚÒ»Æð£º
{ "people": [ { "firstName": "Brett", "lastName":"McLaughlin", "email": "brett@newInstance.com" }, { "firstName": "Jason", "lastName":"Hunter", "email": "jason@servlets.com" }, { "firstName": "Elliotte", "lastName":"Harold", "email": "elharo@macfaq.com" } ]}
Õâ²»ÄÑÀí½â¡£ÔÚÕâ¸öʾÀýÖУ¬Ö»ÓÐÒ»¸öÃûΪ peopleµÄ±äÁ¿£¬ÖµÊÇ°üº¬Èý¸öÌõÄ¿µÄÊý×飬ÿ¸öÌõÄ¿ÊÇÒ»¸öÈ˵ļǼ£¬ÆäÖаüº¬Ãû¡¢Ðպ͵ç×ÓÓʼþµØÖ·¡£ÉÏÃæµÄʾÀýÑÝʾÈçºÎÓÃÀ¨ºÅ½«¼Ç¼×éºÏ³ÉÒ»¸öÖµ¡£µ±È»£¬¿ÉÒÔʹÓÃÏàͬµÄÓï·¨±íʾ¶à¸öÖµ£¨Ã¿¸öÖµ°üº¬¶à¸ö¼Ç¼£©£º
{ "programmers": [ { "firstName": "Brett", "lastName":"McLaughlin", "email": "brett@newInstance.com" }, { "firstName": "Jason", "lastName":"Hunter", "email": "jason@servlets.com" }, { "firstName": "Elliotte", "lastName":"Harold", "email": "elharo@macfaq.com" } ], "authors": [ { "firstName": "Isaac", "lastName": "Asimov", "genre": "science fiction" }, { "firstName": "Tad", "lastName": "Williams", "genre": "fantasy" }, { "firstName": "Frank", "lastName": "Peretti", "genre": "christian fiction" } ], "musicians": [ { "firstName": "Eric", "lastName": "Clapton", "instrument": "guitar" }, { "firstName": "Sergei", "lastName": "Rachmaninoff", "instrument": "piano" } ] }
¡¡