gpt4 book ai didi

iphone - JSON 响应显示在警报 View 中?

转载 作者:行者123 更新时间:2023-11-29 04:16:57 25 4
gpt4 key购买 nike

我是 iPhone 开发新手,我有一个要求,比如我需要在警报 View 中显示 JSON 响应(例如:当我提供错误的详细信息时,我有一个登录页面,我从服务器收到响应,我需要在警报中显示响应看法)这是我的代码

-(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];



}

最佳答案

如果您只想显示带有消息的警报 View ,请执行以下操作:

UIAlertView *alert = [[UIAlertView alloc] initWithTitle: @"Your Title" 
message: @"Your message"
delegate: nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
[alert release];

这将打开一个模态警报 View (即,在您点击“确定”之前不会有任何触摸通过)按钮。

因此只需将 JSON 响应放入消息中(如果需要,请将其转换为可读字符串)

关于iphone - JSON 响应显示在警报 View 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13568984/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com