[ת]¾«Í¨JSON (JavaScript Object Notation)
[ת×Ô]http://article.yeeyan.org/view/mouse4x/16540
JSON±»¹«ÈÏΪä¯ÀÀÆ÷ÖÐXMLµÄºó¼ÌÕߣ¬ËüµÄÄ¿±ê½ö½öÊdzÉΪһÖÖ¼òµ¥¡¢ÓÅÑŵÄÊý¾Ý¸ñʽ£¬ÒÔ·½±ãä¯ÀÀÆ÷ºÍ·þÎñÆ÷Ö®¼äµÄÊý¾Ý½»»»¡£ÔÚÍê³ÉÕâÒ»¼òµ¥ÈÎÎñµÄ¹ý³ÌÖУ¬Ëü½«ÒýÁìÏÂÒ»´úÍòάÍø¡£
¶ÔÏó¼ò½é
¿´,Õâ¾ÍÊÇÒ»¸ö¶ÔÏó:
var myFirstObject ={};
¾¡¹Ü¿´ÆðÀ´Í¦¼òµ¥£¬È»¶øÄÇЩ»¨À¨ºÅÈ´Äܹ»¼Ç¼ÈËÀàËùËѼ¯µÄÐÅÏ¢µÄÿ¸ö±ÈÌØ£¬»òÕßÊDZíʾ³ö¼ÆËã»ú¿Æѧ¼ÒÃÇÄܹ¹Ë¼µ½µÄ×ÔӵijÌÐò.ÊÂʵÉÏ£¬Javascript±¾Éí¾ÍÊÇ´æ´¢ÔÚÄÇÑùÒ»¸ö»¨À¨ºÅ¼¯ºÏÖеģ¬°üÀ¨ËüËùÓеĻù±¾ÀàÐÍ -- ×Ö·û´®,Êý×Ö,Êý×é,ÈÕÆÚ,ÕýÔò±í´ïʽ,ËüÃǶ¼ÊǶÔÏó,¶¼ÊÇÏñÉÏÃæmyFirstObjectÄÇÑù¿ªÊ¼µÄ.
´´½¨Ò»¸öжÔÏó
¾ÉµÄ·½Ê½ÊÇʹÓÃ"new"¹Ø¼ü×Ö´´½¨Ð¶ÔÏó.
var myJSON =newObject();
ÕâÖÖ·½Ê½ÒѾ¹ýʱ,ÏÖÔÚÁ÷Ðеķ½Ê½ÊÇͨ¹ýÒ»¶Ô´óÀ¨ºÅ¶¨ÒåÒ»¸ö¿Õ¶ÔÏó...
var myJSON ={};
¶ÔÏó¼´Êý¾Ý
ÔÚJavascript¶ÔÏóµÄ×îµ×²ãÊÇÒ»ÖÖºÜÁé»îÇÒ½¡×³µÄÊý¾Ý¸ñʽ£¬±íʾΪ“Ãû/Öµ¶Ô”¡£Ò²¾ÍÊÇ˵,Ò»¸ö¶ÔÏóµÄÊôÐÔÃû--¿ÉÒÔ¿´×÷ÊÇÒÀ¸½ÔÚ¶ÔÏóÃûÉϵÄÒ»¸öÆÕͨ±äÁ¿.²¢ÇÒÕâ¸ö¶ÔÏó±£´æ×ÅÉÏÊöÃû×ÖµÄÖµ.¿´ÏÂÃæµÄÀý×Ó...
var myFirstJSON ={"firstName":"John",
"lastName" :"Doe",
"age" :23};
document.writeln(myFirstJSON.firstName); // Êä³öJohn
document.writeln(myFirstJSON.lastName); // Êä³öDoe
document.writeln(myFirstJSON.age); // Êä³ö23
Õâ¸ö¶ÔÏóÓÐ3¸öÊôÐÔ»òÕß˵Ãû/Öµ¶Ô.ÔÚÕâ¸öÀý×ÓÖÐ,firstName,lastName,»¹ÓÐageÕâЩÃû×ÖÊÇ×Ö·û´®ÀàÐÍ.¶øÖµ¿ÉÒÔÊÇÈÎºÎµÄ javascript¶ÔÏó(Çë¼ÇסjavascriptÖÐÒ»Çнé¶ÔÏó,ËùÒÔÕâ¸öÖµ¿ÉÒÔÊÇ×Ö·û´®,Êý×Ö,Êý×é,º¯Êý,»¹ÓÐÆäËü¶ÔÏóÀàÐÍ) -- ÔÚÕâ¸öÀý×ÓÖÐ,ÎÒÃǵÄÖµÊÇJohn,Doe,»¹ÓÐ23.JohnÓëDoeÊÇ×Ö·û´®µ«ageÊÇÊý×Ö,ÈçÄãËù¼û,Õⶼ²»ÊÇÎÊÌâ.
ÕâÖÖÊý¾Ý¸ñʽ³ÆΪJSON,JSONÊÇJavaScript Object NotationµÄËõд.ËüÄÜÈç´ËÇ¿´óµÄÔÒòÊÇËüµÄÖµ¿ÉÒÔÊÇÈκÎÊý¾ÝÀàÐÍ,Äã¿ÉÒÔ±£´æ²»Í¬µÄÊý×éÓë¶ÔÏó,°´ÄãµÄÐèҪȥ¾¡ÇéǶÌ×.ÏÂÃæÊÇÒ»¸öÉԵȸ´ÔÓµãµÄJSON½á¹¹...
var employees ={"accounting":[ // accounting is an array in employees.
Ïà¹ØÎĵµ£º
Ò³ÃæÌá½»Êý¾ÝÒ»°ãÓÐÁ½ÖÖ·½·¨£ºget,post¡£post¾ÍÊÇËùνµÄformÌá½»£¬Ê¹ÓÃÊÓͼ£»getÊÇͨ¹ýurlÌá½»¡£
Get·½·¨Ò»°ãÓúǫ́´úÂ루Èçasp,asp.net£©»ñµÃ²ÎÊý£¬´úÂëºÜ¼òµ¥£ºRequest.QueryString["id"];¼´¿É»ñÈ¡¡£
ÓÐЩʱºòÐèÒªÖ±½ÓÔÚǰ̨»ñÈ¡url²ÎÊý£¬ÒªÓõ½javascript£¬jsûÓÐÖ±½Ó»ñÈ¡url²ÎÊýµÄ·½·¨£¬ÄÇô£¬ÎÒÃÇÈçºÎͨ¹ýjs ......
Nested Members ǶÌ׳ÉÔ±
Since object members may contain other members, it's not uncommon to see patterns such as window.location.href in JavaScript code. These nested members cause the JavaScript engine to go through the object member resolution process each time a dot is ......
µÚÈýÕ DOM Scripting DOM±à³Ì
DOM scripting is expensive, and it's a common performance bottleneck in rich web applications. This chapter discusses the areas of DOM scripting that can have a negative effect on an application's responsiveness and gives recommendations o ......
JavaScriptʼþ´óÈ«
click() ¶ÔÏó.click() ʹ¶ÔÏó±»µã»÷¡£
closed ¶ÔÏó.closed ¶ÔÏó´°¿ÚÊÇ·ñÒѹرÕtrue/false
clearTimeout(¶ÔÏó) Çå³ýÒÑÉèÖõÄsetTimeout¶ÔÏó
clearInterval(¶ÔÏó) Çå³ýÒÑÉèÖõÄsetInterval¶ÔÏó
confirm("ÌáʾÐÅÏ¢") µ¯³öÈ·ÈÏ¿ò£¬È·¶¨·µ»ØtrueÈ¡Ïû·µ»Øfalse
cursor:Ñùʽ ¸ü¸ÄÊó±êÑùÊ ......
3¡¢×éºÏ¹¹Ô캯Êý/ÔÐÍ·½Ê½Ð´À࣬²ÉÓÃÇ°ÃæÖÖ·½Ê½¼Ì³Ð
ÕâÖÖ·½Ê½¸¸À࣬×ÓÀàµÄÊôÐÔ¶¼¹ÒÔÚ¹¹Ô캯ÊýÀ·½·¨¶¼¹ÒÔÚÔÐÍÉÏ¡£
/**
* ¸¸ÀàPolygon:¶à±ßÐÎ
*/
function Polygon(sides) {
this.sides = sides;
}
Polygon.prototype.setSides = function(s) {this.sides=s;}
/**
* Triangle Èý½ÇÐÎ
* @param {Object} b ......