0

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?

PengOne
  • 48,188
  • 17
  • 130
  • 149
Frederick C. Lee
  • 9,019
  • 17
  • 64
  • 105
  • you can put a check before : NSDictionary *myResult = (NSDictionary *)[myString JSONValue]; e.g. NSDictionary *myResult =nil; if([myString length]>0){myResult = (NSDictionary *)[myString JSONValue];} – Saurabh Passolia Jan 11 '12 at 18:50
  • The code that you posted doesn't make sense. And you seem to use a library without telling us which one. – gnasher729 Aug 01 '14 at 21:38

1 Answers1

0

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.

LJ Wilson
  • 14,445
  • 5
  • 38
  • 62