JSONJoy-Swift icon indicating copy to clipboard operation
JSONJoy-Swift copied to clipboard

Array of Object Not working

Open chathuralakmal opened this issue 7 years ago • 0 comments

I have JSON array like this.

{
    "id": "7397632",
    "studentid": "554",
    "daily_attendance": [
        {
            "period_id": "29",
            "attendance_type_id": "1"
        },
        {
            "period_id": "30",
            "attendance_type_id": "1"
        },
        {
            "period_id": "31",
            "attendance_type_id": "1"
        },
        {
            "period_id": "32",
            "attendance_type_id": "1"
        }
    ]
},
{
    "id": "5397643",
    "studentid": "626",
    "daily_attendance": [
      
      {
            "period_id": "30",
            "attendance_type_id": "1"
        },
        {
            "period_id": "31",
            "attendance_type_id": "1"
        },
        {
            "period_id": "32",
            "attendance_type_id": "1"
        }
    ]
}

This is my class

import JSONJoy struct StudentTimeTable : JSONJoy {

let id : String?
let studentid : String?
let daily_attendance : [Daily_attendance]?


init(_ decoder: JSONLoader) throws {
    id = try decoder["id"].get()
    studentid = try decoder["studentid"].get()
    //daily_attendance = try [Daily_attendance(decoder["daily_attendance"])]
    daily_attendance = try decoder["daily_attendance"].get()
}

Problem is it does not create the 'daily_attendance' array Object.

chathuralakmal avatar Jan 24 '18 09:01 chathuralakmal