1
嗨,我是新的iOS開發。在上面的代碼中,我調用了一個web服務,該服務的響應格式爲json。我想用該Web服務的響應來進行json解析。爲什麼數組和字典的值在json解析中顯示爲空?
這裏,爲什麼json和registartion的值在控制檯plz中顯示爲null幫助我。
這裏是我的WebSerVice.h文件
@interface WebService : NSObject<NSURLConnectionDelegate ,NSURLConnectionDataDelegate> {
NSMutableData *data;
NSArray * registrationDetail;
}
-(void)callWebService;
@end
這裏我的網站WebService.m文件
@implementation WebService
-(void)callWebService {
NSString *JsonString =[ NSString stringWithFormat:@"http://bia.igreentechservices.com/ws/ws_registration.php?emailid=%@&password=%@&fname=%@&lname=%@&gender=%@&birthdate=%@&mobile=%@&address=%@&emergency_contact_no=%@&other_contact_no_1=%@&other_contact_no_2=%@",emailAdd,pwd,fName,lName,gen,bDate,mobileNum,add,emergencyContactNum,anotherContactNum1,anothercontactNum2]
UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
NSURL *url = [NSURL URLWithString:JsonString];
NSURLRequest *request =[NSURLRequest requestWithURL:url];
NSURLConnection *myConnection =[[NSURLConnection alloc] initWithRequest:request delegate:self];
[myConnection start];
}
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
data= [[NSMutableData alloc] init];
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)theData {
[data appendData:theData];
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection {
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
NSString *responseString = [[NSString alloc]
initWithData:data encoding:NSUTF8StringEncoding];
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
registrationDetail = [json objectForKey:@"registration"];
NSLog(@"%@",json);
NSLog(@"%@",registrationDetail);
NSLog(@"%@",responseString);
NSLog(@"%@",data);
}