0

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 ?

4

1 に答える 1

1

あなたが提示したコードの外に何か問題があります。次のコードで新しいプロジェクトを作成すると、エラーは発生せず、コンソールには文字列の最初の行が表示されます。

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]);
于 2012-10-27T06:21:06.743 に答える