0

In ios i am using Xml soap parsing This is my response

<InsertResponse xmlns="http://OrderMe.solyn.in/"><InsertResult>[{"Result":"Success","AccessToken":"f60da1f1-40d7-483d-880a-82348dc20934","AppUserId":"35"}]</InsertResult></InsertResponse>

Then i am using This code for Get Response

-(void)parser:(NSXMLParser *) parser foundCharacters:(NSString *)string {
    if (elementFound) {
       // NSLog(@"%@",soapResults);
        [soapResults appendString: string];
        if ([Type isEqualToString:@"InsertResponse"] ) {
            //--- Retrieving text of an element that is found---
            NSLog(@"%@",string);
            NSString *str = [[NSString alloc]initWithData:string encoding:NSUTF8StringEncoding];
            NSArray *allData = [str JSONValue];

            //NSString *loginID=[NSString stringWithFormat:@"%@",string];
            //NSLog(@"Login ID Returned from web service is : %@",loginID);
        }
    }
}

in this code ** NSLog(@"%@",string);** this string is print

[{"Result":"Success","AccessToken":"f60da1f1-40d7-483d-880a-82348dc20934","AppUserId":"35"}]

so i dont know how to convert this string in array I am wating response please share your valuable knowledge Regards, Nishant Chandwani Thanks .

2 Answers 2

1

You need to parse this string as JSON:

NSString *string = @"[{\"Result\":\"Success\",\"AccessToken\":\"f60da1f1-40d7-483d-880a-82348dc20934\",\"AppUserId\":\"35\"}]";
NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
Sign up to request clarification or add additional context in comments.

Comments

0

First this is xml parser.So how can we get the values from this.Let's come to below coding

In your .h part

//Step 1 : Add the Delegate classes

     First of all you should add <NSXMLParserDelegate>

//Step 2 : Create necessary objects

     NSXMLParser *parser;
     NSMutableData *ReceviedData;
     NSMutableString *currentStringValue;

     NSMutableArray *arrayResult;
     NSMutableArray *arrayAccessToken;
     NSMutableArray *arrayAppUserId;

In your .m part

 //Step 3 - Allocate your all  Arrays in your viewDidLoad method

     arrayAppUserId = [NSMutableArray alloc]init];
     arrayResult = [NSMutableArray alloc]init];
     arrayAccessToken = [NSMutableArray alloc]init];

 //Step 4 - Create Connection in your viewDidLoad Like 

     [self createConnection:@"http://www.google.com"];//give your valid url.

-(void)createConnection:(NSString *)urlString
{
     NSURL *url = [NSURL URLWithString:urlString];

  //Step 5 - parser delegate methods are using NSURLConnectionDelegate class or not.
    BOOL success;
    if (!parser)
    {
      parser = [[NSXMLParser alloc] initWithContentsOfURL:url];
      parser.delegate = self;
      parser.shouldResolveExternalEntities = YES;
      success = [parser parse];
      NSLog(@"Success : %c",success);
    }
  }

   -(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
  {
      NSLog(@"Current Element Name : %@",elementName);

     if ([elementName isEqualToString:@"Result"])
     {
         NSLog(@"The Result is==%@",elementName);
     }
     if ([elementName isEqualToString:@"AccessToken"])
     {
         NSLog(@"The AccessToken is==%@",elementName);
     }
     if ([elementName isEqualToString:@"AppUserId"])
     {
         NSLog(@"The appUserId is==%@",elementName);
     }
  }

  -(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
  {
    currentStringValue = [[NSMutableString alloc] initWithString:string];
     NSLog(@"Current String Value : %@",currentStringValue);
  }

  -(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
   {
     if ([elementName isEqualToString:@"Result"])
     {
       [arrayResult addObject:currentStringValue];
     }
     if ([elementName isEqualToString:@"AccessToken"])
     {
       [arrayAccessToken addObject:currentStringValue];
     }
     if ([elementName isEqualToString:@"AppUserId"])
     {
       [arrayAppUserId addObject:currentStringValue];
     }
      currentStringValue = nil;
  }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.