Получать данные я научился, а потом попробовал воспользоваться генератором на jsoncafe.com в SwiftyJSON, но увы
class RootClass : NSObject, NSCoding{
var byTeacher : String!
var disc : String!
var duration : String!
var group : String!
var status : String!
var timeOut : String!
var user : String!
/**
* Instantiate the instance using the passed json values to set the properties values
*/
init(fromJson json: JSON!){
if json.isEmpty{
return
}
byTeacher = json["by_teacher"].stringValue
disc = json["disc"].stringValue
duration = json["duration"].stringValue
group = json["group"].stringValue
status = json["status"].stringValue
timeOut = json["time_out"].stringValue
user = json["user"].stringValue
}
/**
* Returns all the available property values in the form of [String:Any] object where the key is the approperiate json key and the value is the value of the corresponding property
*/
func toDictionary() -> [String:Any]
{
var dictionary = [String:Any]()
if byTeacher != nil{
dictionary["by_teacher"] = byTeacher
}
if disc != nil{
dictionary["disc"] = disc
}
if duration != nil{
dictionary["duration"] = duration
}
if group != nil{
dictionary["group"] = group
}
if status != nil{
dictionary["status"] = status
}
if timeOut != nil{
dictionary["time_out"] = timeOut
}
if user != nil{
dictionary["user"] = user
}
return dictionary
}
/**
* NSCoding required initializer.
* Fills the data from the passed decoder
*/
@objc required init(coder aDecoder: NSCoder)
{
byTeacher = aDecoder.decodeObject(forKey: "by_teacher") as? String
disc = aDecoder.decodeObject(forKey: "disc") as? String
duration = aDecoder.decodeObject(forKey: "duration") as? String
group = aDecoder.decodeObject(forKey: "group") as? String
status = aDecoder.decodeObject(forKey: "status") as? String
timeOut = aDecoder.decodeObject(forKey: "time_out") as? String
user = aDecoder.decodeObject(forKey: "user") as? String
}
/**
* NSCoding required method.
* Encodes mode properties into the decoder
*/
func encode(with aCoder: NSCoder)
{
if byTeacher != nil{
aCoder.encode(byTeacher, forKey: "by_teacher")
}
if disc != nil{
aCoder.encode(disc, forKey: "disc")
}
if duration != nil{
aCoder.encode(duration, forKey: "duration")
}
if group != nil{
aCoder.encode(group, forKey: "group")
}
if status != nil{
aCoder.encode(status, forKey: "status")
}
if timeOut != nil{
aCoder.encode(timeOut, forKey: "time_out")
}
if user != nil{
aCoder.encode(user, forKey: "user")
}
}
}
AF.request(url, method: .get).responseData { [self] response in
switch response.result {
case .success(_):
var json = JSON(response.value!)
print(json)
let user = RootClass(fromJson: json)
print(user.group)
case .failure(_):
print("Ошибка при запросе данных \(String(describing: response.error))")
return
}
}
Вот текст самого JSON
[
{
"duration" : "62",
"status" : "IN",
"time_out" : "23:51:18",
"user" : "Зенковский Александр Михайлович",
"group" : "КТбо2-10",
"by_teacher" : "0",
"disc" : "лек_Высшая_математика"
},
{
"duration" : "46",
"status" : "OUT",
"time_out" : "15:56:35",
"user" : "Зенковский Александр Михайлович",
"group" : "КТбо2-10",
"by_teacher" : "0",
"disc" : "лек_Высшая_математика"
}
]