ios – How one can map variable variety of nested objects in object mapper swift


I’ve a JSON response (bellow) and I have to parse this –

    "name":"Fahim Rahman",
            "firstName": "Imtiaz",
            "lastName": "Khan",
            "avatar_url": null
            "identify":"xcek cert etsh tnhg",
            "identify":"jfd uyt you to",
        "some random key":{
            "identify": "some identify",

To parse this in my code I’ve created this mannequin. I can’t in a position to parse the teams as that’s not a listing however an object –

    import ObjectMapper
    class Particular person: BaseObject {
        @objc dynamic var ID: Int = -1
        @objc dynamic var identify: String = ""
        @objc dynamic var age: Int = -1
        var friendsList = Checklist<Pals>()
        override func mapping(map: ObjectMapper.Map) {
            ID <- map["id"]
            identify <- map["name"]
            age <- map["age"]
            friendsList <- map["friends"]

    class Pals: BaseObject {
        @objc dynamic var firstName: String = ""
        @objc dynamic var lastName: String = ""
        @objc dynamic var avatarURL: String = ""
        override func mapping(map: ObjectMapper.Map) {
            firstName <- map["firstName"]
            lastName <- map["name"]
            age <- map["lastName"]
            avatarURL <- map["avatar_url"]

I do know it is a unhealthy JSON. The teams needs to be on the listing as a substitute of the nested objects however sadly, I am getting this response.

Right here within the response of teams, the variety of nested objects is dynamic and the important thing of the nested object can be dynamic. Thus I can’t in a position to parse this as associates attribute.

So my query is, how can I map the “teams”?


Leave a Reply