我已经在我的应用程序中使用了该项目,并在我想在视图控制器的其他部分中使用的部分中使用了AFJSONRequest
它返回的数据。success
我这辈子都想不通。我创建了一个属性来保存数据,但我无法在其他方法中访问它。这有什么原因吗?这可能是我做错了什么。如何在其他方法中使用 nameArray、emailArray 和 passArray?它们已经被声明为属性。这是我的代码:
- (void)viewDidLoad
{
[super viewDidLoad];
NSURL *url = [NSURL URLWithString:@"http://10.247.245.87/it/emailmanager.php"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[AFJSONRequestOperation addAcceptableContentTypes:[NSSet setWithObject:@"text/html"]];
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON)
{
NSLog(@"email.last_name is of type: %@", [[JSON valueForKeyPath:@"email.lastname" ] class]);
nameArray = [JSON valueForKeyPath:@"email.last_name"];
emailArray = [JSON valueForKeyPath:@"email.email_address"];
passArray = [JSON valueForKeyPath:@"email.password"];
NSLog(@"%@", nameArray);
}
failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON)
{
NSLog(@"error %@ %@", [error description], JSON);
}];
[operation start];
}
这是其余的。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
EMailCell* cell = [tableView dequeueReusableCellWithIdentifier:@"EmailCell"];
cell.nameLabel.text = @"%@", nameArray;
cell.emailLabel.text = @"%@", emailArray;
cell.passLabel.text = @"%@", passArray;
return cell;
}
以下是 JSON 结果的结构:
2012-11-13 07:43:46.026 IT Tools[13987:c07] Names: (
{
code = 0496;
department = Management;
"email_address" = "????@???.com";
"first_name" = John;
id = 227;
"last_name" = Doe;
password = "T0496)$(^";
store = Toyota;
},
调试器控制台的结果:
2012-11-13 09:04:37.416 IT Tools[15386:c07] email.last_name is of type: __NSArrayI