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:

JQuery Ajax Tutorial or Lession


JQuery Ajax Tutorial

  1. Lesson Introduction
  2. Key Concepts
  3. jQuery Ajax-Related Methods
  4. jQuery  Ajax-Related Methods Reviewed
  5. Ajax and Forms
  6. Working with JSON
  7. Working with JSON Reviewed
  8. Ajax Events
  9. Load External Content
  10. Load Content Using JSON
  11. Load Exercises Reviewed