Reputation: 1
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
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