JSON: NSString stringWithContentsOfURL... with null in stream, crashes

528 views Asked by At

Environment: iOS 4.3+ using Xcode 4.3+

I'm always getting an iOS/Xcode crash when I implement the following string that returns data with nulls in it:

[NSString stringWithContentsOfURL:myURL encoding:NSUTF8StringEncoding error:&error]; 
NSDictionary *myResult =  (NSDictionary *)[myString JSONValue];

The result:

-[NSNull isEqualToString:]: unrecognized selector sent to instance 0x17315e8

When the data stream contains no nulls (mostly), it works fine. Is this a known problem?

Any remedy?

1

There are 1 answers

1
LJ Wilson On

You can also fix the data coming in from the source. In almost all of my web service interaction, I use COALESCE on queries and SP's to make sure that the data coming out is always consistent.