So I changed the structure in attempt to follow the hierarchal tree because I keep getting nil when trying to print out what I thought would be the title. I have trying a lot of different lines of code just to print out one of the key value pairs. With no luck. Keep getting nil. I must be doing something wrong. Can some one help?
Here is the update swift file containing the structures.
//
// claude31.swift
// GetData
//
// Created by Gregory Kaiser on 9/8/22.
//
import Foundation
struct MP4: Codable {
var _480: String?
}
struct Videos: Codable {
var mp4: MP4?
}
struct ROWS: Codable {
var title:String?
var description:String?
var Poster:String?
}
struct RESP: Codable{
var totalRows: Int
var rows: [ROWS]
}
struct Kaiserclixresponse : Codable {
var error: Bool
var message: String?
var resp: RESP
}
Here is the viewController code trying to access the JSON
//
// ViewController.swift
// GetData
//
// Created by Gregory Kaiser on 9/6/22.
//
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
// Hit the API endpoint
guard let url = URL(string:"https://videos.kaiserclix.com/AVideo/plugin/API/get.json.php?APIName=video&user=gkaiser63@gmail.com&pass=abc123") else {
fatalError("Invalid URL")
}
URLSession.shared.dataTask(with: url) { (data, response, error) in
// Check for errors
guard let data = data, error == nil else {
return
}
//Parse JSON
let result = try? JSONDecoder().decode(Kaiserclixresponse.self, from: data)
if let result = result {
print(result.resp.rows[0].Poster!)
}
}.resume()
}
}