2

I am getting response from web-service like this

Result =     (
            (
        "Test1",
        "Test2",
        "Test3",
        "Test4",
        Test5
    )
);

By, [dict objectForKey:@"Result"]; I am getting value

(
        "Test1",
        "Test2",
        "Test3",
        "Test4",
        Test5
    )

So, how can I get values in array format from NSSting format.

For eg. Array :- Test1, Test2, Test3, Test4, Test5

Can anyone reply please.

Thanks in advance.

1
  • 1
    Please give us more information on what you are receiving from the web-service. The Result you've shown is not ObjC at all so we have no clues to understand which datatype is being used. Commented Aug 27, 2012 at 10:32

5 Answers 5

3

try This Code :

NSMutableArray* arrCountryName = (NSMutableArray *)[yourString componentsSeparatedByString: @","];
Sign up to request clarification or add additional context in comments.

1 Comment

Why are you casting to NSMutableArray. Seems not a sensible things to do here.
1

If you copied the printout exactly as formatted, it appears that the @"Result" key contains an array of arrays with a single element which is already the array that you wanr, so this should work for you:

NSArray *res = [[dict objectForKey:@"Result"] objectAtIndex:0];

The reason I think this is an array in an array is that it shows two levels of nested parentheses around the list.

Comments

1

Here you can use your inputString and generate the Array output as follows:

NSString *inputString = @"Test1,Test2,Test3,Test4";
NSMutableArray* outputArray = [[NSMutableArray alloc] init];
outputArray = [inputString componentsSeparatedByString: @","];

If you need any more help them let me know.

Comments

0

try this:

if([dict objectForKey:@"Result"] isKindofClass:[NSArray class]])
{

   NSArray *arrValues = [dict objectForKey:@"Result"];
  //u have your array 
  for(NSString *value in arrValues)
  {
    NSLog(@"%@",values);
  }
}

Comments

0
NSString *separatorString = @",";
NSScanner *aScanner = [NSScanner scannerWithString:yourString];
NSString *thingsScanned;
[aScanner scanUpToString:separatorString intoString:&thingsScanned];
NSLog(@"container: %@", thingsScanned);

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.