请帮我调试代码无法识别的选择发送到实例在JSON解析
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(queue, ^{
NSError *error = nil;
NSURL *urls = [NSURL URLWithString:[NSString stringWithFormat:@"http://cnapi.iconnectgroup.com/api/UserProfile?id=1"]];
NSString *json = [NSString stringWithContentsOfURL:urls encoding:NSASCIIStringEncoding error:&error];
NSLog(@"JSon data = %@ and Error = %@", json, error);
if(!error)
{
NSData *jsonData = [json dataUsingEncoding:NSASCIIStringEncoding];
NSArray *myJsonArray = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:nil];
NSLog(@"JSON data is :: %@", myJsonArray);
for(NSDictionary *jsonDictionary in myJsonArray)
{
//NSString *uids = jsonDictionary[@"UID"];
NSString *address1 = jsonDictionary[@"Address1"];
NSString *address2 = jsonDictionary[@"Address2"];
NSString *city = jsonDictionary[@"City"];
NSString *emailId = jsonDictionary[@"EmailID"];
NSString *fname = jsonDictionary[@"FName"];
NSString *fax = jsonDictionary[@"Fax"];
NSString *lname = jsonDictionary[@"LName"];
NSString *password = jsonDictionary[@"Password"];
NSString *phone = jsonDictionary[@"Phone"];
NSString *state = jsonDictionary[@"State"];
NSString *uids = [jsonDictionary objectForKey:@"UID"];
NSString *zip = jsonDictionary[@"Zip"];
NSString *company = jsonDictionary[@"company"];
NSString *department = jsonDictionary[@"department"];
NSLog(@"Uid is = %@", uids);
NSLog(@"First Name = %@", fname);
NSLog(@"Last Name = %@", lname);
NSLog(@"Company = %@", company);
NSLog(@"Email Id = %@", emailId);
NSLog(@"Password = %@", password);
NSLog(@"Department = %@", department);
NSLog(@"Address 1 = %@", address1);
NSLog(@"Address 2 = %@", address2);
NSLog(@"City = %@", city);
NSLog(@"State = %@", state);
NSLog(@"Zip = %@", zip);
NSLog(@"Phone = %@", phone);
NSLog(@"Fax = %@", fax);
}
}
});
[activity stopAnimating];
self.activity.hidden = YES;
}
图片会给你错误所在。点击stepover进行调试后出现此错误。我也试过
NSString *address1 = [jsonDictionary objectForKey:@"Address1"];
当你记录myJsonArray的内容时,你在控制台上看到了什么? –
你确定jsonDictionary是一个NSDictionary,我认为它是一个字符串 –
显示你的myJsonArray – wesley