Я пытаюсь использовать (https://collegescorecard.ed.gov/data/documentation/) для заполнения таблицы в моем приложении ios, но данные не отображаются. Я пробовал свои ключи API и URL несколько раз, поэтому я не думаю, что это так. Структура файла json
Школа категории Dev
Имя Строка Название учреждения (INSTNM), как указано в IPEDS.
import UIKit
import Alamofire
class ViewController: UIViewController {
let URLStr = "https://api.data.gov/ed/collegescorecard/v1/schools?fields=school.name"
var resultArray = [Users]()
@IBOutlet weak var tableView: UITableView!
@IBOutlet weak var searchBar: UISearchBar!
var searchCollege = [String]()
override func viewDidLoad() {
super.viewDidLoad()
tableView.dataSource = self
tableView.delegate = self
callAPI()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
func callAPI() {
let key = "key redacted"
//let url = URL(string:"\(URLStr)?api_key=\(key)")
let url = URL(string:"\(URLStr)&api_key=\(key)")
print(url)
Alamofire.request(url!, method: .get, parameters: nil, headers:[:]).responseJSON {(response) in
if let responseObj = response.value as? [[String: Any]]{
self.resultArray = self.parseJSON(userData: responseObj)
print("response here", response)
self.tableView.reloadData()
}
}
}
func parseJSON(userData: [[String:Any]])-> [Users] {
var userArr = [Users]()
for obj in userData {
do { let data = try JSONSerialization.data(withJSONObject: obj, options: .prettyPrinted)
let decodedData = try JSONDecoder().decode(Users.self, from: data)
userArr.append(decodedData)
}
catch {
}
}
return userArr
}
}
userModal.swift
mport Foundation
struct Users: Codable {
let userSchool_name: String?
}
enum CodingKeys: String, CodingKey {
case userSchool_name = "school.name"
}
Я пытался распечатать ответ и различные объекты, но ничего не печаталось. У меня есть функция ниже, которая отображает ее в приложении, но я не думаю, что это проблема.
json output
SUCCESS: {
metadata = {
page = 0;
"per_page" = 20;
total = 7112;
};
results = (
{
"school.name" = "West Michigan College of Barbering and Beauty";
},
{
"school.name" = "Georgia College & State University";
},
{
"school.name" = "Georgia Southern University";
},
{
"school.name" = "Clayton State University";
},
{
"school.name" = "Andrew College";
},
{
"school.name" = "Columbus Technical College";
},
{
"school.name" = "Georgia Northwestern Technical College";
},
{
"school.name" = "Atlanta Metropolitan State College";
},
{
"school.name" = "Clark Atlanta University";
},
{
"school.name" = "Augustana College";
},
{
"school.name" = "Miami Ad School at Portfolio Center";
},
{
"school.name" = "Tricoci University of Beauty Culture-Urbana";
},
{
"school.name" = "University of Hawaii at Manoa";
},
{
"school.name" = "Aveda Institute-Twin Falls";
},
{
"school.name" = "Cameo Beauty Academy";
},
{
"school.name" = "Truett McConnell University";
},
{
"school.name" = "Cannella School of Hair Design-Chicago";
},
{
"school.name" = "Valdosta State University";
},
{
"school.name" = "American Academy of Art";
},
{
"school.name" = "City Colleges of Chicago-Kennedy-King College";
}
);
}