你好,我有一个问题,我有一个json url,这个json url返回下面的json内容;
{"ROW”:2,”COLUMN”:[“Name”,”Surname”],"DATA”:{“Name”:[“your_name”,”your_name1”],“Surname”:[“your_surname”,”your_surname1”]}}但对于我来说,需要这个json格式来转换Swift UITableView,我测试了SwiftyJson,但我的问题不能正确工作。Im创建了一个数组,UITableView和im将这个数组正确地插入到UITableView中,但是我不知道如何将这个json内容添加到UITableView中。非常感谢。
我的Swift代码:
let animalArray = ["Firsname","Firsname","Firsname"]
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView:UITableView, numberOfRowsInSection section: Int)-> Int{
return animalArray.count
}
func tableView(_ tableView:UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell{
let cell = tableView.dequeueReusableCell(withIdentifier: "MyCell", for:indexPath)
cell.textLabel!.text = animalArray[indexPath.row]
return cell
}发布于 2020-05-30 03:25:16
例如,您应该首先在viewDidLoad()中获取JSON,将其值赋给在视图控制器中声明的某个var或let,然后以与刚才相同的方式使用它。Guide to fetch and decode JSON
注您的结构必须是JSON的精确副本。因为它是
{
"ROW”: 2,
”COLUMN”:[“Name”,”Surname”],
"DATA”: { “Name”: [“your_name”,”your_name1”],
“Surname”: [“your_surname”,”your_surname1”] }
}你的结构必须是
struct JSONStruct: Codable {
var ROW: Int
var COLUMN: [String]
var DATA: Dictionary<String: [String]>
}https://stackoverflow.com/questions/62090892
复制相似问题