Open sam961 opened 3 years ago
I have the below model and i need to map the array of object directly to the model without creating two models
one for 'childActivityList' and the other for nested array object
can i take the values directly?
childId <- map["childActivityList.0.childId"]
The above will always take the first value
In other words...i need to get rid of childActivityList
"data": { "childActivityList": [ { "childId": "34bad8a5-0315-4d9f-a948-4780ed266040", "childName": "Test Produkte", "childImage": "https://testurl/s.png", "appName": "TikTok Lite", "appPackageName": "com.zhiliaoapp.musically.go", "appTime": "2167120", "openTime": "1619012403405", "deviceName": "Test Produkte_Android Tablet", "appIcon": null, "location": "Tirana", "isBlocked": false, "message": "now active on TikTok Lite" } }
class ActivityModel: Mappable, Encodable { var appName : String? var appPackageName : String? var appTime : String? var appIconURL:String? var deviceName : String? var id : String? var location : String? var openTime : String? var profileImage : String? var childName : String? var childImage : String? var message : String? required init?(map: Map) { } func mapping(map: Map) { appName <- map["appName"] appPackageName <- map["appPackageName"] appTime <- map["appTime"] deviceName <- map["deviceName"] id <- map["id"] location <- map["location"] openTime <- map["openTime"] profileImage <- map["profileImage"] appIconURL <- map["appIcon"] childName <- map["childName"] }
let activities = baseModel?.data?.childActivityList
I exepected something like:
Correct Model
nil values
I have the below model and i need to map the array of object directly to the model without creating two models
one for 'childActivityList' and the other for nested array object
can i take the values directly?
childId <- map["childActivityList.0.childId"]
The above will always take the first value
In other words...i need to get rid of childActivityList
Your JSON dictionary:
Your model:
What you did:
What you expected:
I exepected something like:
What you got: