Question

Ok boys and girls, this is my prob :

I'd like to read a JSON stream in my iOS app, but when i tried, it returns

2013-04-12 02:35:01.479 Test[81414:303] (null)

but my file exist and is absolutely not empty !! You can find it here http://api.kalokod.com/cce/mainfeed.json

And my script to read it is :

NSError *error;

    NSURL *file = [NSURL URLWithString:@"http://api.kalokod.com/cce/mainfeed.json"];


    NSString *string = [NSString stringWithContentsOfURL:file
                                                encoding:NSUTF8StringEncoding
                                                   error:&error];

    NSLog(@"%@", string);
Was it helpful?

Solution

I tested your code, and received a Cocoa Error 261. This means that the JSON you are trying to load isnt encoded with UTF-8, so using NSUTF8StringEncoding wont work. Try this

NSString *string = [NSString stringWithContentsOfURL:file
                                            encoding:NSASCIIStringEncoding
                                               error:&error];

OTHER TIPS

I suspect this might be your problem -- that there are non-UTF8 characters in your JSON string.

Log your NSError *error to see if you get a Cocoa error 261.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top