hi i am trying to get values from mysql to display in Xcode textfield.but i got (null) values in text field.. my Xcode ...
- (IBAction)find:(id)sender {
NSError *err;
NSString *strURL=[NSString stringWithFormat:@"http://192.168.1.15:81/priya/sam.php?FirstName=%@",name.text];
NSData *dataURL=[NSData dataWithContentsOfURL:[NSURL URLWithString:strURL]];
NSString *strResult=[[NSString alloc] initWithData:dataURL encoding:NSUTF8StringEncoding];
NSLog(@"got response==%@", strResult);
NSDictionary *jsonArray = [NSJSONSerialization JSONObjectWithData:dataURL options: NSJSONReadingMutableContainers error:&err];
NSArray *array=[jsonArray objectForKey:@"key"];
address.text=[NSString stringWithFormat:@"%@", [[array objectAtIndex:0]objectForKey:@"firstName"]];
phone.text=[NSString stringWithFormat:@"%@", [[array objectAtIndex:1]objectForKey:@"lastname"]];
}
and my php code..
<?php
$host = "localhost";
$user = "xcode";
$pass = "xcode";
$db="xcode";
$r = mysql_connect($host, $user, $pass);
echo mysql_get_server_info() . "
";
$r2 = mysql_select_db($db);
$result1 = mysql_query("SELECT * FROM Persons WHERE FirstName='{$_GET['FirstName']}'");
$result=array();
while($row = mysql_fetch_array($result1))
array_push($result,array('firstName' => $row[0],'lastname'=>$row[1]));
echo json_encode(array("key" => $result));
mysql_close();
?>
and also i got JSON values in console
{"key":[{"firstName":"Peter","lastname":"Griffin"},{"firstName":"Peter","lastname":"Griffin"}]}
help me to find answer for this . thanks in advance.