JSON

Json°´Ä³¸ö¼üµÄÖµ½øÐÐÅÅÐò

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

ÕâƪÎÄÕÂÖ÷Òª½éÉÜÁËjson°´Ä³¸ö¼üµÄÖµ½øÐÐÅÅÐòµÄÏà¹Ø×ÊÁÏ,´úÂë¼òµ¥Ò׶®£¬·Ç³£²»´í£¬ÐèÒªµÄÅóÓÑ¿ÉÒԲο¼ÏÂ

Json°´Ä³¸ö¼üµÄÖµ½øÐÐÅÅÐò

×÷ÕߣºÌðÃà ×ÖÌ壺[ ] ÀàÐÍ£º×ªÔØ Ê±¼ä£º2016-12-22

ÕâƪÎÄÕÂÖ÷Òª½éÉÜÁËjson°´Ä³¸ö¼üµÄÖµ½øÐÐÅÅÐòµÄÏà¹Ø×ÊÁÏ,´úÂë¼òµ¥Ò׶®£¬·Ç³£²»´í£¬ÐèÒªµÄÅóÓÑ¿ÉÒԲο¼ÏÂ

ÏÂÃæÊÇjs´úÂ룺£¨Ç뽫Æä±£´æΪsortJson.js£©

$(document).ready(function () { //¶Ôjson½øÐнµÐòÅÅÐòº¯Êý var colId="age" var desc = function(x,y) { return (x[colId] < y[colId]) ? 1 : -1 } //¶Ôjson½øÐÐÉýÐòÅÅÐòº¯Êý var asc = function(x,y) { return (x[colId] > y[colId]) ? 1 : -1 } var arr2 = [ {name:"kitty", age:12}, {name:"sonny", age:9}, {name:"jake", age:13}, {name:"fun", age:24} ]; document.writeln("°´age½øÐÐÉýÐòÅÅÐò£º<br>"); arr2.sort(asc); //ÉýÐòÅÅÐò document.writeln(JSON.stringify(arr2)); document.writeln("<br>°´age½øÐнµÐòÅÅÐò£º<br>"); arr2.sort(desc); //½µÐòÅÅÐò document.writeln(JSON.stringify(arr2)); });

ÏÂÃæÊÇhtml´úÂ룺

<!DOCTYPE html> <html> <head> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=gbk" /> <script type="text/javascript" src="http://lib.sinaapp.com/js/jquery/1.7.2/jquery.min.js"></script> <script type="text/javascript" src="sortJson.js"></script> </head> <body> </body> </html>

ÏÂÃæÊÇÅÅÐòµÄ½á¹û£º

ÒÔÉÏËùÊöÊÇС±à¸ø´ó¼Ò½éÉܵÄJson°´Ä³¸ö¼üµÄÖµ½øÐÐÅÅÐò£¬Ï£Íû¶Ô´ó¼ÒÓÐËù°ïÖú£¬Èç¹û´ó¼ÒÓÐÈκÎÒÉÎÊÇë¸øÎÒÁôÑÔ£¬Ð¡±à»á¼°Ê±»Ø¸´´ó¼ÒµÄ¡£ÔÚ´ËÒ²·Ç³£¸Ðл´ó¼Ò¶Ô½Å±¾Ö®¼ÒÍøÕ¾µÄÖ§³Ö£¡

Äú¿ÉÄܸÐÐËȤµÄÎÄÕÂ:

Tags£º

Ïà¹ØÎÄÕÂ

×îÐÂÆÀÂÛ

¡¡

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

Ïà¹ØÎÄÕÂ
ÍøÓѵãÆÀ
¨