I was under the assumption - maybe I can't read documentation - that IsValidJSONObject would check to see if the Foundation object could be turned into a JSON object.
From the docs: isValidJSONObject: Returns a Boolean value that indicates whether a given object can be converted to JSON data. I was hoping to scan the results of a URL call to see if the returned data was legit before trying to convert it. Thanks for clearing this up for me. On Mar 6, 2012, at 3:46 PM, Fritz Anderson wrote: > On 6 Mar 2012, at 1:59 PM, Alex Zavatone wrote: > >> Yeah, I've got the JSON down to this: >> >> [1] >> >> and >> {"A":1} >> >> And the code: >> BOOL isTurnableToJSON = [NSJSONSerialization isValidJSONObject: >> responseData]; >> NSLog(@"Is legit for JSON: %d", isTurnableToJSON ); >> NSLog(@"Is legit for JSON: %@", isTurnableToJSON ? @"YES" : @"NO"); // >> this is how we handle a bool :/ > > Wait — am I to understand you are passing a JSON string to > isValidJSONObject:? I can't make sense of your citing JSON strings as problem > cases otherwise, but in your original message you talk about _emitting_ JSON. > > The method goes the other way around. It determines whether a tree of > Foundation objects can be translated _into_ JSON. NSJSONSerialization won't > accept anything but container objects, so passing a string won't validate > even fortuitously. > > The method names are inexpressive. > > — F > _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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 arch...@mail-archive.com