欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

包含jsonjquery的詞條

jQuery處理json數(shù)據(jù)返回?cái)?shù)組和輸出的方法

這篇文章主要介紹了jQuery處理json數(shù)據(jù)返回?cái)?shù)組和輸出的方法,涉及jQuery操作數(shù)組及json的技巧,需要的朋友可以參考下

成都創(chuàng)新互聯(lián)總部坐落于成都市區(qū),致力網(wǎng)站建設(shè)服務(wù)有網(wǎng)站建設(shè)、成都網(wǎng)站設(shè)計(jì)、網(wǎng)絡(luò)營(yíng)銷(xiāo)策劃、網(wǎng)頁(yè)設(shè)計(jì)、網(wǎng)站維護(hù)、公眾號(hào)搭建、小程序制作、軟件開(kāi)發(fā)等為企業(yè)提供一整套的信息化建設(shè)解決方案。創(chuàng)造真正意義上的網(wǎng)站建設(shè),為互聯(lián)網(wǎng)品牌在互動(dòng)行銷(xiāo)領(lǐng)域創(chuàng)造價(jià)值而不懈努力!

本文實(shí)例講述了jQuery處理json數(shù)據(jù)返回?cái)?shù)組和輸出的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:

代碼如下:

/*print

the

json

object

*

*$("selector").print_r_json(json,opts)

:

return

formatted

string

(and

print)

*sprint_r_json

:

just

return

the

string;

*print_r_json

:

return

the

formatted

string

and

print

json

data

*contribute

明河

*

*auth

iorichina

*

*example:

*3

ways

to

use

it

*script

language="javascript"

*$("selector").print_r_json({"a":"aa","d":{"ef":{"a":"d","d":["a","b"]},"ed":"dd"},"g":"g"},{if_print:true,return_array:true});

*document.write($.sprint_r_json({"a":"aa","d":{"ef":{"a":"d","d":["a","b"]},"ed":"dd"},"g":"g"}));

*$.print_r_json({"a":"aa","d":{"ef":{"a":"d","d":["a","b"]},"ed":"dd"},"g":"g"});

*/script

*

*/

$.fn.print_r_json

=

function(json,options){

if(typeof(json)!="object")

return

false;

var

opts

=

$.extend({},$.fn.print_r_json.defaults,options);

var

data

=

'';

if(opts.if_print)

{

data

=

$.sprint_r_json(json)

$(this).html('div

style="font-weight:bold"'+(opts.return_array?'Array':'JSON-DATA')+'/div'+data);

}

if(opts.array)

{

return

$.json_to_array(json);

}

return

data;

};

$.fn.print_r_json.defaults

=

{

if_print

:

false,//if

print

or

just

return

formatted

string

return_array

:

true

//return

an

Array

};

$.extend({

print_r_json

:

function(json)

{

if(typeof(json)=="object")

{

var

text='div

style="font-weight:bold;"{/divdiv

style="margin-left:25px;"';

document.write('div

style="font-weight:bold;"{/divdiv

style="margin-left:25px;"');

for(var

p

in

json)

{

if(typeof(json[p])=="object")

{

document.write('div["'+p+'"]

=

');

text+='div["'+p+'"]

=

'+$.print_r_json(json[p])+'/div';

document.write('/div');

}

else

{

text+='div['+((/^d+$/).test(p)?p:('"'+p+'"'))+']

=

"'+json[p]+'"/div';

document.write('div['+p+']

=

'+json[p]+'/div');

}

}

text+='/divdiv

style="font-weight:bold;"}/div';

document.write('/divdiv

style="font-weight:bold;"}/div');

return

(text);

}

else

{

document.write(json);

return

(json);

}

},

sprint_r_json

:

function(json)

{

if(typeof(json)=="object")

{

var

text

=

'div

style="font-weight:bold;"{/divdiv

style="margin-left:25px;"';

for(var

p

in

json)

{

if(typeof(json[p])=="object")

{

text

+=

'div["'+p+'"]

=

'+$.sprint_r_json(json[p])+'/div';

}

else

{

text

+=

'div['+((/^d+$/).test(p)?p:('"'+p+'"'))+']

=

"'+json[p]+'"/div';

}

}

text

+=

'/divdiv

style="font-weight:bold;"}/div';

return

(text);

}

else

{

return

(json);

}

},

json_to_array

:

function(json)

{

if(typeof(json)=="object")

{

var

text

=

new

Array();

for(var

p

in

json)

{

if(typeof(json[p])=="object")

{

text[p]

=

$.json_to_array(json[p]);

}

else

{

text[p]

=

json[p];

}

}

return

(text);

}

else

{

return

(json);

}

}

});

希望本文所述對(duì)大家的jQuery程序設(shè)計(jì)有所幫助。

請(qǐng)問(wèn)JQUERY和JSON的聯(lián)系和區(qū)別。是不是非得會(huì)JSON??請(qǐng)舉例說(shuō)明。

JQUERY 是一個(gè)JS的框架, JSON是一種數(shù)據(jù)的表現(xiàn)形式. 現(xiàn)在JSON已經(jīng)成為一種標(biāo)準(zhǔn)的 WEB前端通訊標(biāo)準(zhǔn)數(shù)據(jù)格式, 建議還是認(rèn)真學(xué)會(huì), 挺容易的. 當(dāng)然, JQUERY對(duì)于 JSON是絕對(duì)支持的. 甚至在 1.6.1以后的版本, 對(duì)于 AJAX方法的參數(shù)傳遞都必須嚴(yán)格按照J(rèn)SON的格式進(jìn)行規(guī)范

jquery對(duì)象怎么轉(zhuǎn)化成json對(duì)象

jquery中沒(méi)有這樣的方法,只有將字符串轉(zhuǎn)換為對(duì)象的方法:jQuery.parseJSON( json)。 如果將object對(duì)象轉(zhuǎn)換為json字符串,在現(xiàn)代瀏覽器中可以用JSON.stringify()這個(gè)原生方法。在IE6/7以及IE8兼容模式中,可以先引用之后再采用JSON.stringify()。

jQuery怎么解析Json字符串

Jquery解析json字符串、json數(shù)組

!doctype html

html

head

meta charset="utf-8"

script src="../js/libs/jquery-1.6.2.min.js"/script

/head

body

hr /

h3解析json字符串、json數(shù)組/h3

input type="button" id="jsonBtn" name="jsonBtn" value="jsonArray" /

input type="button" id="jsonArray2" name="jsonArray2" value="jsonArray2" /

input type="button" id="jsonStr" name="jsonStr" value="jsonStr" /

input type="button" id="jsonStr2" name="jsonStr2" value="jsonStr2" /

hr /

div class="jsonText"

{"ret": 0, "msg": "", "is_lost":0, "nickname": "小米", "gender": "男", "province": "廣東", "city": "廣州", "year": "1990", "figureurl": "http:\/\/qzapp.qlogo.cn\/qzapp\/101152201\/D87BF108B19279F31587CE96E5648A98\/30", "figureurl_1": "http:\/\/qzapp.qlogo.cn\/qzapp\/101152201\/D87BF108B19279F31587CE96E5648A98\/50", "figureurl_2": "http:\/\/qzapp.qlogo.cn\/qzapp\/101152201\/D87BF108B19279F31587CE96E5648A98\/100", "figureurl_qq_1": "http:\/\/q.qlogo.cn\/qqapp\/101152201\/D87BF108B19279F31587CE96E5648A98\/40", "figureurl_qq_2": "http:\/\/q.qlogo.cn\/qqapp\/101152201\/D87BF108B19279F31587CE96E5648A98\/100", "is_yellow_vip": "0", "vip": "0", "yellow_vip_level": "0", "level": "0", "is_yellow_year_vip": "0"}

/div

hr /

div class="jsonArray"

{ root:

[

{name:'1',value:'0'},

{name:'6101',value:'西安市'},

{name:'6102',value:'銅川市'},

{name:'6103',value:'寶雞市'},

{name:'6104',value:'咸陽(yáng)市'},

{name:'6105',value:'渭南市'},

{name:'6106',value:'延安市'},

{name:'6107',value:'漢中市'},

{name:'6108',value:'榆林市'},

{name:'6109',value:'安康市'},

{name:'6110',value:'商洛市'}

],

json:

[

{name:'6103',value:'寶雞市'},

{name:'6104',value:'咸陽(yáng)市'},

{name:'6107',value:'漢中市'},

{name:'6108',value:'榆林市'},

{name:'6110',value:'商洛市'}

]

}

/div

hr /

div class="jsonArray2"

[

{name:'1',value:'0'},

{name:'6101',value:'西安市'},

{name:'6102',value:'銅川市'},

{name:'6103',value:'寶雞市'},

{name:'6104',value:'咸陽(yáng)市'},

{name:'6105',value:'渭南市'},

{name:'6106',value:'延安市'},

{name:'6107',value:'漢中市'},

{name:'6108',value:'榆林市'},

{name:'6109',value:'安康市'},

{name:'6110',value:'商洛市'}

]

/div

/body

/html

script type="text/javascript"

///jQuery 解析json字符串

//解析復(fù)雜的json數(shù)組

$("#jsonBtn").click(function(){

var data=$(".jsonArray").html();

alert("-----"+data);

var dataObj=eval("("+data+")");//轉(zhuǎn)換為json對(duì)象

alert(dataObj.root.length);//輸出root的子對(duì)象數(shù)量

alert(dataObj.json.length);//輸出json的子對(duì)象數(shù)量

//遍歷json數(shù)組

$.each(dataObj.root, function(i, item) {

alert(item.name+"-----root-------"+item.value);

});

//遍歷json數(shù)組

$.each(dataObj.json, function(i, item) {

alert(item.name+"-----json-------"+item.value);

});

});

//解析單個(gè)的json數(shù)組

$("#jsonArray2").click(function(){

var data=$(".jsonArray2").html();

alert("-----"+data);

var dataObj=eval("("+data+")");//轉(zhuǎn)換為json對(duì)象

alert(dataObj.length);//輸出root的子對(duì)象數(shù)量

//遍歷json數(shù)組

$.each(dataObj, function(i, item) {

alert(item.name+"-----jsonArray-------"+item.value);

});

});

///解析標(biāo)準(zhǔn)的Json串 方法一

$("#jsonStr").click(function(){

var json=$(".jsonText").html();

alert("---2--"+json);

var item = jQuery.parseJSON(json);

alert(item.nickname);

alert(item.ret);

alert(item.figureurl );

});

///解析標(biāo)準(zhǔn)的Json串,方法二

$("#jsonStr2").click(function(){

var json=$(".jsonText").html();

alert("---2--"+json);

var obj = eval("("+json+")");

alert(obj.nickname);

alert(obj.ret);

alert(obj.figureurl );

});

/script

jquery如何返回json數(shù)據(jù)?

$.ajax({?

url:?ajaxurl,

type:?"POST",

success:?function(data){

//假設(shè)返回的json數(shù)據(jù)里有status及info2個(gè)屬性

//有時(shí)候可以直接ajaxobj.status或者ajaxobj["status"]去訪問(wèn)??

//但有時(shí)候,卻要通過(guò)eval()或者?$.parsejson();才可以通過(guò)ajaxobj.status訪問(wèn),而且這種情況下,需要是complete而不是success

ajaxobj=eval("("+data+")");

//或者$.parsejson()

//var?ajaxobj?=?$.parsejson(data);

if(ajaxobj.status=="0")

{

alert("請(qǐng)登陸.");

}

else?if(ajaxobj.status=="1")//未綁定微博

{

alert(ajaxobj.info);

}

return?true;

},

error:function(ajaxobj)

{

if(ajaxobj.responseText!='')

alert(ajaxobj.responseText);

}

});

新聞標(biāo)題:包含jsonjquery的詞條
分享路徑:http://chinadenli.net/article4/dsgjeoe.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站收錄云服務(wù)器營(yíng)銷(xiāo)型網(wǎng)站建設(shè)微信小程序定制開(kāi)發(fā)標(biāo)簽優(yōu)化

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

手機(jī)網(wǎng)站建設(shè)