【发布时间】:2015-10-13 18:49:04
【问题描述】:
在我的 PHP 后端,我返回一个 JSON,如下所示:
$results_array=array();
$stmt->bind_result($IdUser,$username);
while($stmt->fetch()) {
$row = array();
$row["IdUser"]=$IdUser;
$row["username"]=$username;
$results_array[]=$row;
}
$stmt->close();
echo json_encode(array("Response"=>"Login okay", "code"=>200, "results"=>$results_array));
我的 AFHTTPRequestOperation 管理器返回 responseObject(命名结果)。
现在我要获取用户:
NSDictionary *user = (NSDictionary *)[results objectForKey:@"results"];
NSLog(@"%@",user);
[[API sharedInstance] setUser:user];
[self.navigationController popViewControllerAnimated:YES];
[self showAlertWithTitle:@"Logged in" andMessage:[NSString stringWithFormat:@"Welcome %@",[user objectForKey:@"username"]]];
应用程序因"NSInvalidArgumentException', reason: '-[__NSCFArray objectForKey:]: unrecognized selector sent to instance" 而崩溃。我正在使用 NSLog 检查“用户”对象,我得到:
{ IdUser = 49; 用户名=肯尼; }
仍然是 JSON 格式。我在这里做错了什么?为什么它不反序列化为 NSDictionary 中的 NSDictionary?
【问题讨论】:
标签: php ios objective-c json afnetworking