I have
var contacts : [ContactsModel] = []
and
class ContactsModel: NSObject
{
var contactEmail : String?
var cont
Your custom object can't be converted to JSON
directly. NSJSONSerialization Class Reference says:
An object that may be converted to JSON must have the following properties:
The top level object is an NSArray or NSDictionary.
All objects are instances of NSString, NSNumber, NSArray, NSDictionary, or NSNull.
All dictionary keys are instances of NSString.
Numbers are not NaN or infinity.
You might convert your object to a Dictionary
manually or use some libraries like SwiftyJSON, JSONModel or Mantle.
Edit: Currently, with swift 4.0+, you can use Codable
protocol to easily convert your objects to JSON. It's a native solution, no third party library needed. See Using JSON with Custom Types document from Apple.