Towhid
Towhid

Reputation: 1

obj-C parsing a string

I have a NSString which looks like this

{
ISOcountryCode = US;
administrativeArea = Texas;
coordinate = "11.761241, -99.496531";
country = "United States";
formattedAddress = "45,North Virinia,VA, USA";
}

I tried the following code segment. But getting 'NSInvalidArgumentException' error. Not sure. what's wrong. It's a JSON output. Here 'result' is my string which contains the above info.

NSArray *array = [result componentsSeparatedByString:@"\n"];             
NSLog(@"%@",[array objectAtIndex:0]);

Any info on how to parse this string so I can get info like country, coordinate etc ?

Upvotes: 0

Views: 106

Answers (1)

Nathanial Woolls
Nathanial Woolls

Reputation: 5291

There is something wrong outside of the code you presented. If you create a new project with the following code, you'll ge no error and the console will display the first line of your string;

NSString *result = @"{ \n"
    "ISOcountryCode = US; \n"
    "administrativeArea = Texas; \n"
    "coordinate = ""11.761241, -99.496531""; \n"
    "country = ""United States""; \n"
    "formattedAddress = ""45,North Virinia,VA, USA""; \n"
    "}";

NSArray *array = [result componentsSeparatedByString:@"\n"];
NSLog(@"%@",[array objectAtIndex:0]);

Upvotes: 1

Related Questions