I also find that it is good practice to set variables returned by reference to nil before passing them.
NSError *error = nil; Otherwise, they will contain garbage, and cannot reliably be tested to see if the value was set. Andy is right though, that it is better to test whether jsonObject is nil in this case. Thanks, Jon On Apr 30, 2014, at 1:07 PM, Andy Lee <[email protected]> wrote: > On Apr 30, 2014, at 3:21 PM, Jens Alfke <[email protected]> wrote: >> On Apr 30, 2014, at 8:20 AM, Diederik Meijer | Ten Horses >> <[email protected]> wrote: >> >>> Now here is the problem: although the JSON parses fine and populates a >>> UITableView without any issues, I am still getting the following error: >> >> If the JSON parsed fine, then the error must be coming from somewhere else. >> A call to JSONObjectWithData: either returns a parsed object, or returns nil >> and sets the error. It doesn’t do both :) > > Which means... > >> NSError *error; >> id jsonObject = [NSJSONSerialization JSONObjectWithData:self.container >> options:NSJSONReadingAllowFragments error:&error]; >> if (error) { >> NSLog(@"ERROR: %@", error); >> } >> else { > > ...you shouldn't be testing error, you should be checking whether jsonObject > is nil, and only then look at the error. Doing it the wrong way around could > explain false errors. For example, NSJSONSerialization could pessimistically > stick an error object in there as the default error, but manage to parse > successfully and return a non-nil object. But then I'm not sure how you > could *also* be having your table populated with the right objects. > > --Andy > > > _______________________________________________ > > Cocoa-dev mailing list ([email protected]) > > Please do not post admin requests or moderator comments to the list. > Contact the moderators at cocoa-dev-admins(at)lists.apple.com > > Help/Unsubscribe/Update your Subscription: > https://lists.apple.com/mailman/options/cocoa-dev/jhull%40gbis.com > > This email sent to [email protected] _______________________________________________ Cocoa-dev mailing list ([email protected]) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [email protected]
