ÓÃjquery½âÎöJSONÊý¾ÝµÄ·½·¨£¨×ª£©
ÕâÀïÊ×Ïȸø³öJSON×Ö·û´®¼¯£¬×Ö·û´®¼¯ÈçÏ£º
´úÂëÈçÏÂ:
var data=" <br /> { <br /> root: <br /> [ <br /> {name:'1',value:'0'}, <br /> {name:'6101',value:'±±¾©ÊÐ'}, <br /> {name:'6102',value:'Ìì½òÊÐ'}, <br /> {name:'6103',value:'ÉϺ£ÊÐ'}, <br /> {name:'6104',value:'ÖØÇìÊÐ'}, <br /> {name:'6105',value:'μÄÏÊÐ'}, <br /> {name:'6106',value:'ÑÓ°²ÊÐ'}, <br /> {name:'6107',value:'ººÖÐÊÐ'}, <br /> {name:'6108',value:'ÓÜÁÖÊÐ'}, <br /> {name:'6109',value:'°²¿µÊÐ'}, <br /> {name:'6110',value:'ÉÌÂåÊÐ'} <br /> ]<br /> }";
ÕâÀïÒÔjqueryÒì²½»ñÈ¡µÄÊý¾ÝÀàÐÍ¡ª¡ªjson¶ÔÏóºÍ×Ö·û´®ÎªÒÀ¾Ý£¬·Ö±ð½éÉÜÁ½ÖÖ·½Ê½»ñÈ¡µ½µÄ½á¹û´¦Àí·½Ê½¡£
1.¶ÔÓÚ·þÎñÆ÷·µ»ØµÄJSON×Ö·û´®£¬Èç¹ûjqueryÒì²½ÇëÇóû×öÀàÐÍ˵Ã÷£¬»òÕßÒÔ×Ö·û´®·½Ê½½ÓÊÜ£¬ÄÇôÐèÒª×öÒ»´Î¶ÔÏ󻯴¦Àí£¬·½Ê½²»ÊÇÌ«Âé·³£¬¾ÍÊǽ«¸Ã×Ö·û´®·ÅÓÚeval()ÖÐÖ´ÐÐÒ»´Î¡£ÕâÖÖ·½Ê½Ò²ÊʺÏÒÔÆÕͨjavascipt·½Ê½»ñÈ¡json¶ÔÏó£¬ÒÔϾÙÀý˵Ã÷£º
var dataObj=eval("("+data+")");//ת»»Îªjson¶ÔÏó
alert(dataObj.root.length);//Êä³örootµÄ×Ó¶ÔÏóÊýÁ¿
$.each(dataObj.root,fucntion(idx,item){
if(idx==0){
return true;
}
//Êä³öÿ¸öroot×Ó¶ÔÏóµÄÃû³ÆºÍÖµ
alert("name:"+item.name+",value:"+item.value);
})
×¢£º¶ÔÓÚÒ»°ãµÄjsÉú³Éjson¶ÔÏó£¬Ö»ÐèÒª½«$.each()·½·¨Ì滻ΪforÓï¾ä¼´¿É£¬ÆäËû²»±ä¡£
2. ¶ÔÓÚ·þÎñÆ÷·µ»ØµÄJSON×Ö·û´®£¬Èç¹ûjqueryÒì²½ÇëÇó½«type£¨Ò»°ãΪÕâ¸öÅäÖÃÊôÐÔ£©ÉèΪ¡°json¡±£¬»òÕßÀûÓÃ$.getJSON()·½·¨»ñµÃ ·þÎñÆ÷·µ»Ø£¬ÄÇô¾Í²»ÐèÒªeval£¨£©·½·¨ÁË£¬ÒòΪÕâʱºòµÃµ½µÄ½á¹ûÒѾÊÇjson¶ÔÏóÁË£¬Ö»ÐèÖ±½Óµ÷ÓøöÔÏó¼´¿É£¬ÕâÀïÒÔ$.getJSON·½·¨ÎªÀý˵ Ã÷Êý¾Ý´¦Àí·½·¨£º
$.getJSON("http://www.phpzixue.cn/",{param:"gaoyusi"},function(data){
//´Ë´¦·µ»ØµÄdataÒѾÊÇjson¶ÔÏó
//ÒÔÏÂÆäËû²Ù×÷ͬµÚÒ»ÖÖÇé¿ö
$.each(data.root,function(idx,item){
if(idx==0){
return true;//ͬcountinue£¬·µ»Øfalseͬbreak
}
alert("name:"+item.name+",value:"+item.value);
});
});
ÕâÀïÌرðÐèҪעÒâµÄÊÇ·½Ê½1ÖеÄeval()·½·¨ÊǶ¯Ì¬Ö´ÐÐÆäÖÐ×Ö·û´®£¨¿ÉÄÜÊÇjs½Å±¾£©µÄ£¬ÕâÑùºÜÈÝÒ×»áÔì³ÉϵͳµÄ°²È«ÎÊÌâ¡£ËùÒÔ¿ÉÒÔ²ÉÓÃһЩ¹æ±ÜÁËeval()µÄµÚÈý·½¿Í»§¶Ë½Å±¾¿â£¬±ÈÈçJSON in JavaScript¾ÍÌṩÁËÒ»¸ö²»³¬¹ý3kµÄ½Å±¾¿â¡£
ÍƼöÐÅÏ¢
- jqueryʵÏÖÍøվͼƬÀÁ¼ÓÔØ´úÂë
- jQuery Tooltips²å¼þ
- jQueryµÄ.bind()¡¢.live()ºÍ.delegate(....
- [Ô´´]·ÂGoogle Reader¡¢ÐÂÀË΢²©¡¢ÌÚѶ΢²©µ....
- Ä㲻ϲ»¶»ðºü£¬µ«ÓÖϲ»¶firebug£¬ÄǾ͸úÎÒÒ»ÆðÀ´ÔÚIEÉÏ....
- ¸ù¾ÝÏÔʾÆ÷·Ö±æÂʵ÷ÕûÒ³ÃæÏÔʾµÄJavascript½Å±¾
- jQuery дµÄ·ÂÐÂÀË΢²© ÏòϹö¶¯Ð§¹û¡¾×ªÔØ¡¿
- ͨÓõÄJqueryÑ¡ÔñÆ÷
- jQuery ½áºÏ Json Ìá½»Êý¾Ýµ½Webservice£¬....
- ×ÔÖÆjQueryÖÇÄÜÌáʾ²å¼þһö
ÈÈÃÅÐÅÏ¢
- nohup: redirecting stderr to stdou....
- ʹÓÃlog_formatΪNginx·þÎñÆ÷ÉèÖøüÏêϸµÄÈÕÖ¾¸ñʽ
- jquery easyUI--dataGrid-Json
- [Ô´´]·ÂGoogle Reader¡¢ÐÂÀË΢²©¡¢ÌÚѶ΢²©µ....
- ÀûÓÃKeepalived+mysql¹¹½¨¸ß¿ÉÓÃMySQLË«Ö÷×Ô¶....
- Nginx+keepalivedʵÏÖ¸ºÔؾùºâºÍË«»úÈȱ¸¸ß¿ÉÓÃ
- jqueryʵÏÖÒ³Ãæ¼ÓÔؽø¶ÈÌõ
- Rolling cURL: PHP²¢·¢×î¼Ñʵ¼ù
- codeigniter ·ÓÉÖÕ¼«ÓÅ»¯(url rewrite)
- linuxÏÂÉèÖÃsshÎÞÃÜÂëµÇ¼
×î½ü¸üÐÂ
- js»ñÈ¡srcÖд«µÝµÄ²ÎÊý
- jqueryʵÏÖÍøվͼƬÀÁ¼ÓÔØ´úÂë
- ÈÃä¯ÀÀÆ÷ÆÁ±ÎµôJavaScriptµÄ³ö´íÌáʾ
- github²»ÄܼÓÔØcss¡¢js½â¾ö°ì·¨
- ÎÒÖªµÀµÄJavaScript -- Éè¼Æģʽ(ÇŽÓ)Ó¦ÓÃÖ® ¨C ....
- 15¸öÖµµÃ¿ª·¢ÈËÔ±¹Ø×¢µÄjQuery¿ª·¢¼¼ÇɺÍÐĵÃ
- dz̸JavascriptÃæÏò¶ÔÏó±à³Ì
- JS¼òµ¥¶¯»·â×°
- JavaScript³õѧÕßӦעÒâµÄÆ߸öϸ½Ú
- jQuery Tooltips²å¼þ
ÆÀÂÛ