json returns the value and I store in variable. For example开发者_Go百科
var person = {
Name:"Shree",
Address: "Ratopul",
Profession: "Programmer",
Address: [
{
District: "abc",
Ward: "Tel",
Tel:"235"
},
{
District: "abc1",
Ward: "Tel",
Tel:"235"
},
{
District: "abc2",
Ward: "Tel",
Tel: "235"
}
]
};
I got a address through.
var address=person.Address;
But I want to catch a particular element of address. How is it possible. I don't have any idea. Please help.
var p1= person.Address[0] //first
var p2= person.Address[1] //second
var p3= person.Address[2] //third
alert(p1.Ward);
**or**
for (i=0; i< person.Address.length;i++)
{
var person=person.Address[i];
if(person.Tel===235)
{
//this is the person i was looking for
}
}
Address is just an array of objects.
var district = person.Address[0].District;
Dude is this what u r looking for?
var addresses=person.Address; $.each(addresses,function(index,item){ alert(item.District+"-"+item.Ward); if(item.Tel=="235") { alert(item.District); } });
精彩评论