我是 iphone 开发的新手,我有一个要求,例如我需要在警报视图中显示 JSON 响应(例如:当我提供错误详细信息时,我有一个登录页面我从服务器获得响应我需要在警报视图中显示响应)here我的代码是
-(IBAction)signin:(id)sender{
requestSelect = [[NSMutableURLRequest alloc] initWithURL: [NSURL URLWithString: @"http://abc....?"]];
NSString *requestString = [NSString stringWithFormat:@"request_parameter={\"EmailId\":\"%@\", \"Password\":\"%@\"}",email.text,password.text,nil];
NSLog(@"requestString in subarea %@",requestString);
NSMutableData *requestData =[NSMutableData dataWithBytes: [requestString UTF8String] length: [requestString length]];
[requestSelect setHTTPMethod: @"POST"];
[requestSelect setHTTPBody: requestData];
connection=[[NSURLConnection alloc] initWithRequest:requestSelect delegate:self];
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse: (NSURLResponse *)response{
receiveddata = [[NSMutableData alloc]init ];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)aData{
[ receiveddata appendData:aData];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection{
jsonString = [[NSString alloc] initWithData:receiveddata
encoding:NSUTF8StringEncoding];
dictServerData = [jsonString JSONValue];
valueForKey:@"result"]valueForKey:@"data"] objectAtIndex:0]valueForKey:@"service_status" ]);
arr_login= [[NSArray alloc]initWithArray:[[[[[dictServerData valueForKey:@"webservice"] valueForKey:@"result"]valueForKey:@"data"] objectAtIndex:0]valueForKey:@"service_status" ]];
objectForKey:@"webservice"]objectForKey:@"result"]objectForKey:@"data"]objectAtIndex:0]objectForKey:@"userdetails" ]objectAtIndex:0]);
NSMutableDictionary *DetailsDict=[NSMutableDictionary dictionaryWithObject:[ [[[[[dictServerData objectForKey:@"webservice"]objectForKey:@"result"]objectForKey:@"data"]objectAtIndex:0]objec tForKey:@"userdetails" ]objectAtIndex:0] forKey:@"data"];
NSLog(@"details dict : %@",DetailsDict);
defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:DetailsDict forKey:@"details"];
UpdateDetail *updt =[[UpdateDetail alloc]initWithNibName:@"UpdateDetail" bundle:Nil];
[self.navigationController pushViewController:updt animated:YES];
[updt release];
}