从单个记录或更多记录中读取数据

I have a query which gives data from one person or from more persons. The data for one person is presented with JSON as:

Array ( [0] => Array ( 
 [a2a_Person] => Array ( 
 [pid] => Person1 
 [a2a_PersonName] => Array ( 
 [a2a_PersonNameFirstName] => Array ( [a2a_PersonNameFirstName] => Aagje )  
 [a2a_PersonNameLastName] => Array ( [a2a_PersonNameLastName] => Baltus ) ) ....

If there are more persons then the data is presented as

Array ( [0] => Array ( 
 [a2a_Person] => Array ( 
  [0] => Array ( 
  [pid] => Person1 [a2a_PersonName] => Array ( 
  [a2a_PersonNameFirstName] => Array ( [a2a_PersonNameFirstName] => Walig )
  [a2a_PersonNamePatronym] => Array ( ) 
  [a2a_PersonNamePrefixLastName] => Array ( ) 
  [a2a_PersonNameLastName] => Array ( [a2a_PersonNameLastName] => Verdugt ) ) [a2a_Gender] => Array ( [a2a_Gender] => Man ) 
 [1] => Array ( 
  [pid] => Person2 
  [a2a_PersonName] => Array ( 
  [a2a_PersonNameFirstName] => Array ( [a2a_PersonNameFirstName] => Huibert ) [a2a_PersonNamePatronym.....

My question is now : how can i determine if I have more Person-records so i can acces the data correct way.

And what is the best way to acces the data. Must I first check the definition and write different code.

Thanks, Fred