在 JQUERY 中获取 JSON 数组的第一个元素
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23680568/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Get First element of a JSON Array in JQUERY
提问by Muhammad Umar
I have following JSON STRINg as a result of a jquery function
由于 jquery 函数,我遵循了 JSON STRING
{"error":"","status":"1","data":[{"id":"6","ringSetName":"DFWR0319 - 18K White Gold 30RD.45ctw Pave Halo Engagement Ring(does not include center diamond)","ringSetCategories":"Halo","ringThumbNailImagePath":"http:\/\/thevowapp.com\/iphoneapp\/ringthumbs\/DI004_R_Thumb_White_WBG_00001.jpg","ringOnHandImagePath":"http:\/\/thevowapp.com\/iphoneapp\/handrings\/DI004_R_handring_White_WBG_00001.png","ringSetClientName":"Cherie Dori","ringDescription":"This angel's halo has 30 precision set round brilliant diamonds that wrap around your center diamond. *center diamond sold separately, mounting can be modified for any size or shape center diamond","ringHDir":"http:\/\/thevowapp.com\/iphoneapp\/ringmodels\/NL\/DI004_IPad\/IPad_DI004_H_White_000_Diamond_E_800x600.zip","ringRDir":"http:\/\/thevowapp.com\/iphoneapp\/ringmodels\/NL\/DI004_IPad\/IPad_DI004_R_White_000_Diamond_E_800x600.zip","ringPicDir":"http:\/\/thevowapp.com\/iphoneapp\/ringmodels\/NL\/DI004_IPad\/IPad_DI004_RPic_White_000_Diamond_E_800x600.zip{}http:\/\/thevowapp.com\/iphoneapp\/ringmodels\/NL\/DI004_IPad\/IPad_DI004_RPic_Yellow_000_Diamond_E_800x600.zip","forteenk":"860","eighteenk":"930","platinium":"1,211.00","ringSetKaratQuality":"18K","videos":"http:\/\/vimeo.com\/81502294, http:\/\/vimeo.com\/81502295\r\n","ringWebFolder":"DI004_FWR0319"}]}
Now data is always an array with 1 ELEMENT.
Using this code how can i get value of ringWebFolder
现在数据总是一个有 1 个元素的数组。使用此代码如何获得价值ringWebFolder
.done(function( msg )
{
if( msg.status=="1")
{
var path = 'DiadoriAllrings/'+ msg.data.ringWebFolder; // IT SAYS UNDEFINED
path = path.concat("/No_Logo");
alert(path);
initSwf(path);
} else {
alert("Error : "+msg.error);
}
jQuery('#sliderloading').addClass('hide');
});
回答by pmandell
msg.datais an array with 1 element (an object). You can select the first element in the array by index, then the property of the object.
msg.data是一个包含 1 个元素(一个对象)的数组。您可以通过索引选择数组中的第一个元素,然后是对象的属性。
You can use:
您可以使用:
msg.data[0].ringWebFolder