0

我是 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];



}
4

1 回答 1

1

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

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

这将打开一个模式警报视图(即,在您点击确定之前,不会通过它传递任何触摸)按钮。

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

于 2012-11-26T16:37:35.773 回答