我正在尝试实现“检查重复用户名”首先,我必须得到我的json,它存储了我的所有用户记录。并获取用户名的对象。然后将它们与UItTextField中的文本进行匹配。我的问题是我可以看到我所有的json,但我似乎无法正确解析它。
-(IBAction) ChkUsername: (id) sender {
NSDictionary * userdata = [NSDictionary new];
[DIOSUser userGet: userdata success: ^ (AFHTTPRequestOperation * operation, id response) {
NSLog(@"%@", response);
DIOSSession * session = [DIOSSession sharedSession];
[session setUser: [response objectForKey: @"user"]];
NSDictionary * uname = [
[session user] objectForKey: @"name"];
if ([self.txtUsernameRegister.text isEqualToString: uname]) {
// if([uname isEqual:self.txtUsernameRegister.text]){
NSLog(@"You cannot use this Username");
} else {
NSLog(@"You can use this username");
}
}
failure: ^ (AFHTTPRequestOperation * operation, NSError * error) {
NSLog(@"%@", [error localizedDescription]);
}];
}
我也遇到了这个错误NSCFArray objectForKey:]
这里编辑的是我的JSON的样子。
{
uid: "60",
name: "pae1344",
mail: "viper1344@gmail.com",
theme: "",
signature: "",
signature_format: "plain_text",
created: "1396189622",
access: "0",
login: "1396189622",
status: "1",
timezone: "Asia/Bangkok",
language: "",
picture: "0",
init: "viper1344@gmail.com",
data: null,
uri: "http://localhost/drupal/rest/user/60"
},