我對iphone開發很陌生我有一個需求,比如我需要在alert視圖中顯示JSON響應(例如:我有一個登錄頁面,當我提供錯誤的細節時,我正在從服務器獲取響應,我需要在alert視圖中顯示響應) 這裏我的代碼是JSON響應顯示在提醒vview中?
-(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];
}
究竟什麼是你問的JSON響應?如何用消息顯示警報視圖? – giorashc
是的,我想顯示服務器響應像登錄錯誤或註冊成功。 – feroz