I want to get the json data using the API created by Django and show it in the table view. There is nothing in value in the following program. What should I do?
Json data:
{
"books": [
{
"id": 1,
"name": "Django",
"publisher": "GeekLab Nagano",
"page": 10,
"impressions": []
}]}
Code:
var tableTitle = [String]()
var tableDetail = [String]()
let url:String = "http://127.0.0.1:8000/api/v1/"
func loadData() {
Alamofire.request(url).responseJSON {
response in
guard let value = response.result.value else {
return
}
let json = JSON(value)
let books = json["books"]
for item in books.arrayValue {
self.tableTitle.append(item["name"].stringValue)
self.tableDetail.append(item["publisher"].stringValue)
}
print(self.tableTitle)
print(self.tableDetail)
self.tableView.reloadData()
}
}