ios - SwiftyJSON add array of JSON objects -
i trying serialize object graph json using swiftyjson library. have function in birthdayevent class named "tojson" converts individual birthday events swiftyjson objects successfully.
however keen have following structure json:
"birthdays" : [ { "eventid": "...", "date": "01/01/2000", ... }, { "eventid": "...", "date": "01/02/2001", ... }, ... ] i finding difficult create json dictionary string "birthday" key , array of birthdayevent json items value.
i have following code:
var birthdaysjson: json = json(self.events.map { $0.tojson() }) var jsonoutput : json = ["birthdays": birthdaysjson] the first line creates json object of array of events, cannot seem use in dictionary literal. error of "value of type 'json' not conform expected dictionary value type 'anyobject'.
can tell me going wrong, or over-complicating this?
to create json dictionary, have initialize json object on jsonoutput did birthdaysjson:
var jsonoutput: json = json(["birthdays": birthdaysjson])
Comments
Post a Comment