1

json returns the value and I store in variable. For example

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.

2
  • what does you this mean "i want to catch particular element of address" Commented Aug 7, 2011 at 9:59
  • I mean is it possible to search in address for District which Tel is 235 Commented Aug 7, 2011 at 10:08

3 Answers 3

2
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
        }
    }
Sign up to request clarification or add additional context in comments.

Comments

1

Address is just an array of objects.

var district = person.Address[0].District;

Comments

0

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);
}
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.