Free Subcription

Enter your email address:

Please don't forget to activate link from your inbox


Access the objects inside another objects In the JSON Response Object using JQuery

Most of the AJAX response, we will get the JSON Resonse. Some times we may require to get the object details, inside other object. For this requirement, below code is useful.



<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
    <script type="text/javascript">
        var dataContainer = {
            metaData: {
                Paints: [{
                    id: 1,
                    color: { id: 123456 }
                },
                {
                    id: 2,
                    color: { id: 789 }
                }]
            }
        };
        $(function () {
            debugger;
            $.each(dataContainer.metaData.Paints,function(key,value){
                $('body').append($('<div>').html('<b>Id:</b>' + value.id + '----- <b> Color Code:</b>' + value.color.id));
            });
        });
    </script>
</head>
<body>
</body>
</html>

Output:
Share this post :

Post a Comment

 
Copyright © 2011. JQuery Example Code - All Rights Reserved
JQuery Video Tutorial