0

Am trying to access the data from the following JSON . Am Getting response after hitting the server and i need to access the data present in the information1 field.

{  
   "Test1":[  
      {  
         "id1":0,
         "Test2":[  
            {  
               "Information1":"info1",
               "name":"Testing",
               "defnitions":[  
                  {  
                     "displayname":"displayame"
                  },
                  {  
                     "displayname2":"displayame2"
                  }
               ],
               "information2":"info2"
            }
         ],
         "information3":"info3",
         "information4":"info4"
      }
   ]
}
StackOverFlow
  • 29
  • 1
  • 5

1 Answers1

0

Cause you are using square brackets, it means you have an array. Consequently, to access to your neccessary object you should use:

var data={  
   "Test1":[  
      {  
         "id1":0,
         "Test2":[  
            {  
               "Information1":"info1",
               "name":"Testing",
               "defnitions":[  
                  {  
                     "displayname":"displayame"
                  },
                  {  
                     "displayname2":"displayame2"
                  }
               ],
               "information2":"info2"
            }
         ],
         "information3":"info3",
         "information4":"info4"
      }
   ]
};
var yourObject=data.Test1[0].Test2[0];

To parse JSON response just use stringify method:

var theWholeObject=JSON.stringify(data);

StepUp
  • 36,391
  • 15
  • 88
  • 148
  • @ChandUSiriGiri'S feel free to ask any question. If you feel that my reply helps to you, then you can mark my reply as an answer to simplify future search of other people. Please, read this http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work – StepUp Jun 06 '16 at 18:25