Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
agreatdaytocode
24,757 PointsJSON and NULL values errors
Anyone have a solution for dealing with NULL values that are returned when pulling JSON data?
I'm currently getting the following error message: 2014-06-11 07:11:56.829 [494:6107] LabelValue is =====> 2014-06-11 07:11:56.830[494:613] -[NSNull length]: unrecognized selector sent to instance 0x101b56b50 2014-06-11 07:11:56.846[494:613] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSNull length]: unrecognized selector sent to instance 0x101b56b50' *** First throw call stack: BLA BLA BLA
Example data being returned:
{
dateAdded = "2014-04-22T16:50:32Z";
eventDate = "<null>"; //This is the issue #:(
id = 71496;
name = Test;
ownerName = "name";
webLink = "someurl";
},
2 Answers
Marcus Vieira
7,877 PointsHi Aaron!
You might wanna check if the JSON block has a null element or not:
if (eventDate == (id)[NSNull null]) {
// eventDate is null
}
or you can do:
if (eventDate != (id)[NSNull null]) {
// eventDate is not null
// you are free to parse it :)
}
So you won't have to add an extra else to do your parsing.
I hope this helps!
agreatdaytocode
24,757 PointsMarcus shoot me an email I'll share it with you via GitHub.
agreatdaytocode
24,757 Pointsagreatdaytocode
24,757 PointsHi Marcus, thanks I'll give this a shot.
Marcus Vieira
7,877 PointsMarcus Vieira
7,877 PointsNo problem :) let me know if it works!
agreatdaytocode
24,757 Pointsagreatdaytocode
24,757 PointsYeah I can't get it to work. I'm sure I'm doing something wrong here. I'll keep working on it.
Marcus Vieira
7,877 PointsMarcus Vieira
7,877 PointsIs it still throwing the same error ?
agreatdaytocode
24,757 Pointsagreatdaytocode
24,757 PointsSure is : (
Marcus Vieira
7,877 PointsMarcus Vieira
7,877 PointsCan you show me your parser ?
agreatdaytocode
24,757 Pointsagreatdaytocode
24,757 Points