vendredi 8 mai 2015

Validate an input as JSON notation on iOS

I have an input field on an iOS app that accepts an NSString value. I want to be able to validate the input as a JSON object. For example:

NSString = @"{'foo':'bar'}" //would be validated as JSON notation
NSString = @"Hello world!" //would NOT be validated as JSON

I have tried using the following method:

[NSJSONSerialization isValidJSONObject:(id)obj]

However, it always returns false, even if the string input is something like {'hello':'world'}. Is there anything I'm doing wrong or missing here?

Aucun commentaire:

Enregistrer un commentaire