Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Wunk

macrumors newbie
Original poster
Nov 17, 2008
24
0
Netherlands
I'm trying to set the encoding of a string correctly..

I have a:

NSString *jsonData = [[NSString alloc] initWithContentsOfURL:jsonURL];

The problem is, that when it retreives a character like ä, it'll stick it into the string as √§ (according to the debugger when I NSLog the string)

I've tried doing a:
NSString *jsonData = [[NSString alloc] initWithContentsOfURL:jsonURL encoding:NSUTF8StringEncoding];

But all that gives me is a warning when compiling (warning: no -InitwithContentsOfURL:encoding: method found) and gdb complains with: *** -[NSPlaceholderString initWithContentsOfURL:encoding:]: unrecognized selector sent to instance 0x513f50


Any suggestions on how to correctly populate this NSString with correct encoding ?
 

Wunk

macrumors newbie
Original poster
Nov 17, 2008
24
0
Netherlands
Took a while, but for reference if anyone would ever run into it.., changing the sequence to:

Code:
NSError *lookupError = nil;
NSString *jsonData = [NSString stringWithContentsOfURL:jsonURL
encoding:NSUTF8StringEncoding error:&lookupError];

Makes the encoding go perfect :rolleyes: :apple:
 

kalimba

macrumors regular
Jun 10, 2008
102
0
Well, I guess that makes sense, considering the actual NSString method is indeed "initWithContentsOfURL:encoding:error:". The dead giveaway should have been the compiler warning.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.