2012-11-26 166 views
0

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



} 
+1

究竟什麼是你問的JSON響應?如何用消息顯示警報視圖? – giorashc

+0

是的,我想顯示服務器響應像登錄錯誤或註冊成功。 – feroz

回答

1

如果你只是想顯示一條消息,警報視圖請執行以下操作:

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

這將打開一個模式警報視圖(即無接觸傳遞低谷直到你點擊OK按鈕。

所以只是把信息(如果需要將其轉換爲可讀的字符串)

+0

我不想顯示靜態響應,我需要顯示在服務器 – feroz

+0

我得到的警報respose比使用從服務器獲得的響應對象。如有必要,將其轉換爲字符串 – giorashc