我想将json值传递给可扩展的tableview
我有一个这样的结构
struct Section {
var sites: String
var InnerSites: [String]!
var expanded: Bool
var locations: String
init(sites: String, InnerSites: [String]!, expanded: Bool, locations: String) {
self.sites = sites
self.InnerSites = InnerSites
self.expanded = expanded
self.locations = locations
}
}
我像这样手动传递值
var sec = [Section(sites: String, InnerSites: [String], expanded:
Bool, locations: String)]
这是JSON解析
func siteApi() {
guard let gitUrl = URL(string: "http://example.com/web/sites") else { return }
URLSession.shared.dataTask(with: gitUrl) { (data, response
, error) in
guard let data = data else { return }
do {
let result = try JSONDecoder().decode([JSONObject].self, from: data)
print(result)
for item in result {
print("This is site name \(item.siteName)")
print(item.siteID)
print(item.latitude, item.longitude)
self.mysites.append(item.siteName)
}
} catch let err {
print("Err", err)
}
}.resume()
}
任何人都可以告诉我如何传递json值