You insert booleans into the dictionary using NSNumber . In this case, you can use the literal expression @YES directly, together with the dictionary literal, to make this a single layer:
NSDictionary *jsonDict = @{@"key" : @YES};
To encode it in JSON, use +[NSJSONSerialization dataWithJSONObject:options:error] :
NSError *serializationError; NSData *jsonData = [NSJSONSerialization dataWithJSONObject:jsonDict options:0 error:&serializationError]; if (!jsonData) { NSLog(@"%s: error serializing to JSON: object %@ - error %@", __func__, jsonDict, serializationError]; }
Jeremy W. Sherman
source share