I have a scenario where app reads file from server (dropbox) and checks version. If new version is available then download the app.
I'm trying to read file from link but getting null
after JSON parsing.
NSError *error;
NSString *strFileContent = [NSString stringWithContentsOfURL:[NSURL URLWithString:@"https://www.dropbox.com/s/22mm417fxdqdn8c/FileStructure.txt?dl=0"]
encoding:NSUTF8StringEncoding
error:&error];
if(!error) { //Handle error
// NSLog(@"strFileContent: %@",strFileContent);
NSData *data = [strFileContent dataUsingEncoding:NSUTF8StringEncoding];
id json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
NSLog(@"json : %@",[json description]);
}
else
NSLog(@"Error in reading!");
}
Any alternative to DropBox?
That's not a text file containing JSON; it's an RTF file containing JSON. That won't work with
NSJSONSerialization
:You've saved that file using an editor that uses RTF (the default Mac
TextEdit
). you'll need to re-save as plain text.Provided URL is incorrect too. If you need only file contents you have to set dl=1 (last component of url). Like so -
dropbox.com/s/22mm417fxdqdn8c/FileStructure.txt?dl=1