I want to retrieve data from Array in iOS sent from PHP webservice. Following is the structure of the Array:
[
{
"fullname": "Kate Bell",
"email": "kate-bell@mac.com"
},
{
"fullname": "Kate Bell",
"email": "www.creative-consulting-inc.com"
},
{
"fullname": "Daniel Higgins",
"email": "d-higgins@mac.com"
},
{
"fullname": "John Appleseed",
"email": "John-Appleseed@mac.com"
}
]
Note: Array can be of any length.
PHP code:
mysql_select_db("mydb");
$ReturningArray = array();
foreach($Contacts_Array as $arr)
{
foreach($arr['emails'] as $email_address)
{
$query = "select email from table where email='".$email_address."'";
$result = mysql_query($query);
$row = mysql_fetch_assoc($result);
if(empty($row))
{
$Contact = array(
"fullname" => $arr['fullname'],
"email" => $email_address
);
$ReturningArray[] = $Contact;
}
}
}
echo json_encode($ReturningArray);
Update:
I have tried this code but it doesn't work
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
// NSString *Result = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
// NSLog(@"Result in NonTroopeUsers : %@",Result);
NSArray *array = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
NSLog(@"COUNT :%d",[array count]);
for (NSDictionary* item in array)
{
NSString *fullname = [item objectForKey:@"fullname"];
NSString *email = [item objectForKey:@"email"];
NSLog(@"Full name: %@",fullname);
NSLog(@"email: %@",email);
}
}
Array count is Zero but the commented code shows data recieved in nslog.