请帮忙。
我无法循环 imageUrl。它只返回一个图像而不是遍历所有图像
"images" : [
{
"resturantId" : "919db18e-f5e2-4a6b-1df8-08d747e8c08c",
"id" : "e722f447-a7b8-467c-9b5a-08d747ea79eb",
"imageUrl" : "https:\/\/149356549.v2.pressablecdn.com\/wp-content\/uploads\/2019\/02\/dominos-pizza.jpg"
},
{
"resturantId" : "919db18e-f5e2-4a6b-1df8-08d747e8c08c",
"id" : "e6f42a59-f7a1-4a27-9b5b-08d747ea79eb",
"imageUrl" : "https:\/\/www.pymnts.com\/wp-content\/uploads\/2019\/02\/dominos-earnings-q4-growth.jpg"
},
{
"resturantId" : "919db18e-f5e2-4a6b-1df8-08d747e8c08c",
"id" : "d10e91eb-8d44-477b-9b5c-08d747ea79eb",
"imageUrl" : "http:\/\/apparelmagazine.co.nz\/restaurantandcafe\/wp-content\/uploads\/sites\/3\/2019\/06\/DOminos.jpg?w=640"
}
]
Run Code Online (Sandbox Code Playgroud)
func updateRestImage(json : JSON) {
for for (index, subJson) in json {
if let restuarantName = subJson["images"][0]["imageUrl"].string {
print("jnfvjfvjfvubfuvbfuvb yessssss\(restuarantName)")
}
}
restuarantTableView.reloadData()
}
Run Code Online (Sandbox Code Playgroud)
更改图像索引的值
func updateRestImage(json : JSON) {
let yourRequiredImagesArray = returnJson["images"].arrayValue.compactMap {return Image(data: try! $0.rawData())}
if !yourRequiredImagesArray.isEmpty{
restuarantTableView.reloadData()
}
}
Run Code Online (Sandbox Code Playgroud)
你的模型就像
struct Image: Codable {
let imageUrl
enum CodingKeys: String, CodingKey {
case imageUrl
}
}
extension Image {
init?(data: Data) {
guard let img = try? JSONDecoder().decode(Image.self, from: data) else { return nil }
self = img
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
100 次 |
| 最近记录: |