Search code examples
objective-cnsjsonserialization

How to convert BOOL to JSON with NSJSONSerialization?


How do I add a BOOL to NSMutableDictionary so that I get true when serialized as JSON?

I cannot use NSValue, which is a valid object in the dictionary, but for NSJSONSerialization, NSValue is not working.


Solution

  • Use NSNumber:

    @{ 
       @"foo": @YES
    }