在JQUERY中获取JSON数组的第一个元素

时间:2014-05-15 14:03:17

标签: jquery json

由于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"}]}

现在数据总是一个包含1个ELEMENT的数组。 使用此代码,我如何获得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');

        });

1 个答案:

答案 0 :(得分:6)

msg.data 是一个包含1个元素(对象)的数组。您可以按索引选择数组中的第一个元素,然后选择对象的属性。

您可以使用:

msg.data[0].ringWebFolder