Cannot pass JSON array to array -
i trying pass json array array called array
can query array submission_id
value 27 obtain safety_rating_id
, schedule_job_id
, score
, submission_id
json https://codeshare.io/uqjmv i'm being thrown error
cannot convert value of type '[json]' expected argument type 'json'
code pass json array:
var array: [json] = [] func gettask(oncompletion: () -> (), onerror: ((nserror) -> ())? = nil) { guard let endpoint = data.sharedinstance.weeklyendpoint else { print("empty endpoint"); return } alamofire.request(.get, endpoint, encoding: .json) .validate() .responsejson { response in switch response.result { case .success: if let value = response.result.value { let json = json(value) (_,subjson):(string, json) in json { if let date = subjson["start_date"].string{ self.date = date } if let building = subjson["building_name"].string{ self.building = building } if let jobid = subjson["schedule_job_id"].int { self.jobidarray.append(jobid) } if let tasks = subjson["tasks"].array{ tasks.sharedinstance.datas = tasks building in tasks { if let ratings = building["safety_ratings"].array{ print(ratings) self.array.append(ratings) } } } } oncompletion() } case .failure(let error): print("request failed error: \(error)") onerror?(error) } } }
append()
expects single element (json
), ratings
array ([json]
).
that's error message says.
to append array use appendcontentsof
:
self.array.appendcontentsof(ratings)