tags:

views:

62

answers:

1

I am making a call to a web service, the results of the web service are in a form of a string, separated by delimiters.the result string is 1|101|Y|103|Y|105|Y|107|Y|109|Y|112|N|114|N|116|Y|

Now I tokenize the result string, the first token is 1, and based on this value I display the next menu.

If I do an invalid log in the result is Error

and now second time if I enter the correct user name and password, the first token has a value of Error1.

How am I to get rid of the results obtained in case of invalid log in? My loginController.m file is

 -(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
if( [elementName isEqualToString:@"return"])
{

 recordResults = FALSE;
 **NSArray *chunks=[soapResults componentsSeparatedByString:@"|"];**

 NSLog(soapResult);
 NSLog([chunks objectAtIndex:0]);//Second time on correct login, it displays in console as Error1

 if([[chunks objectAtIndex:0] isEqualToString:@"1"])
 {

  Menu *mv2 = [[Menu alloc] initWithNibName:@"Menu" bundle:nil];
  testAppDelegate *appdel=(testAppDelegate *)[[UIApplication sharedApplication]delegate];
  appdel.soapResult=self.soapResult;
  self.mv1=mv2;
  NSLog(appdel.soapResult);
  [self presentModalViewController:mv1 animated:YES];
  [mv1 release];

 }else {
  //[[chunks objectAtIndex:0] setText:@""];


  UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Sorry Invalid Login"
              delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];

  [alert show];
  [alert release];


  username_TextField.text=@"";
  password_TextField.text=@"";
   }


}

}

- (void)dealloc 
{
[username_TextField release];
[password_TextField release];
[chunks release];
[super dealloc];

}

A: 

This is pretty difficult for me to follow but, let me get this straight:- The first time you -startElement you create an NSMutableString 'soapResults'. Every time you -foundCharacters you append them onto 'soapResults'. Every time you -endElement you parse the ever growing 'soapResults'?

Do you really want to only create one 'soapResults' and keep adding on to it?

actually whenever i loogin i send the username and password to the web service, it authenticates my credentials and returns a string value 1|101|Y|103|Y|105|Y|107|Y|109|Y|112|N|114|N|116|Y| in case of successful login. But in case of invalid login it give me Error as a return string.Now for the first time i enter the invalid credentilas, so my first token or value at [chunks objectAtIndex:0] is Error.Now second time when i enter the correct values , the result should be 1|101|.. and the first token at [chunks objectAtIndex:0] should be 1, However it gives me Error1
shreedevi
so wait. You are saying that [[@"ERROR" componentsSeparatedByString: @"|"] objectAtIndex:0] == @"Error1" ?
**NSArray *chunks=[soapResults componentsSeparatedByString:@"|"];** NSLog(soapResult);//Output: 1|101|Y|103|Y|105|Y|107|Y|109|Y|112|N|114|N|116|Y| But NSLog([chunks objectAtIndex:0]); Output: Error1
shreedevi
wait.. what is 'soapResult' and what is 'soapResults' ?
sorry it is soapResults and not soapResult.
shreedevi
so effectively you're stepping through with the debugger and seeing [[@"1|101|Y|103|Y|105|Y|107|Y|109|Y|112|N|114|N|116|Y|" componentsSeparatedByString: @"|"] objectAtIndex:0] == @"Error1" ?