1

JSON

{
    "form": {
        "roles": {
          "role": [
            { "name": "RoleB" },
            { "name": "RoleA" }
          ]
        },
        "rows":[
            {
                "id":"1",                               
                "fields":{              
                    "field":[
                        {
                            "fname":"Matt"
                        }
                    ]
                }
            }
        ]
    }
}

How can I access the value of fname using jquery?

This is what I'm doing --

jQuery.each(response.form.rows.fields.field, function(i, val){
     alert(this.fname);
}

1 Answer 1

3

Watch out for those arrays....

response.form.rows[0].fields.field[0].fname

Or, in your case (and assuming there's only one rows element):

jQuery.each(response.form.rows[0].fields.field, function(i, val){
     alert(this.fname);
});

If there's more than one element in rows, you need a second loop:

jQuery.each(response.form.rows, function() {
    jQuery.each(this.fields.field, function(i, val) {
        alert(val.fname);
    });
});

http://jsfiddle.net/mblase75/33H8L/

Sign up to request clarification or add additional context in comments.

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.