在越来越显示值误差在Xcode从MySQL?(getting error in display va

2019-10-19 10:19发布

你好我想从MySQL中获取值在Xcode显示textfield.but我得到的文本字段(空)值..我的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"]];
}

和我的PHP代码..

<?php

$host = "localhost"; 
$user = "xcode"; 
$pass = "xcode"; 
$db="xcode";
$r = mysql_connect($host, $user, $pass);
echo mysql_get_server_info() . "\n"; 
$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();
?>

而且我在控制台得到JSON值

 {"key":[{"firstName":"Peter","lastname":"Griffin"},{"firstName":"Peter","lastname":"Griffin"}]}

帮我找到这个答案。 提前致谢。

文章来源: getting error in display values in Xcode from mysql?