要创建来自json类的数据
class getData: NSObject {
var descriptionn : String = ""
var image : String = ""
// static let shared = getData()
func getDataForTableView(results: [[String:String]], index : Int){
var productArray = [String:String]()
productArray = results[index]
descriptionn = productArray["description"]!
image = productArray["images"]!
}
}
在表格视图中显示数据
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "discoveryNewscell") as! DiscoveryNewsTableViewCell
// if results.count > 0{
classObject.getDataForTableView(results: results, index: indexPath.row)
cell.sneakerImageView.image=filteredsneakernews[indexPath.row].image
print("abc image"+classObject.image)
cell.newsTitle.text = classObject.descriptionn
// }
return cell
}
json正在关注foramt
ptional({
data = (
{
"created_date" = "2017-11-09 14:58:58";
"created_on" = "2017-11-09";
"createdd_by" = 3;
description = dfdfdsdfsdfs;
id = 4;
images = "7a53f87882409c4622a0977d5026038b.jpg";
likes = 25;
product = 12;
status = 1;
title = facebook;
"title_keys" = fac;
type = News;
},
{
"created_date" = "2017-11-15 14:33:01";
"created_on" = "2017-11-23";
"createdd_by" = 3;
description = dfdfdf;
id = 7;
images = "e626b8003e6e08df874e33556e7f6e69.jpg";
likes = 3;
product = 0;
status = 1;
title = don;
"title_keys" = don;
type = News;
},
{
"created_date" = "2017-11-16 10:34:48";
"created_on" = "2017-11-13";
"createdd_by" = 3;
description = "my first computer";
id = 8;
images = "556b1855de039b8d99bc787acd103262.jpg";
likes = 90;
product = 13;
status = 1;
title = Dell;
"title_keys" = dell;
type = News;
},
{
"created_date" = "2018-01-02 16:23:54";
"created_on" = "2018-01-08";
"createdd_by" = 3;
description = sdfsdfsfdf;
id = 14;
images = "0c980d3f9cd0393a46bb04995d16177a.jpg";
likes = 0;
product = 0;
status = 1;
title = dfsfdsfdfs;
"title_keys" = " dfsfdsfdfs";
type = News;
}
);
message = "Success.";
newsurl = "http://dev.nsol.sg/projects/sneakers/assets/brand_images/thumb/";
success = 1;
})
此json的图片来自
images = "7a53f87882409c4622a0977d5026038b.jpg";
如何以字符串格式显示图像.Image(classObject.image)如何在表格视图上显示图像视图?您可以从此链接下载代码。https://drive.google.com/file/d/1bVQsuSQINSa6YRwZe2QwEjPpU_m7S3b8/view?usp=sharing
答案 0 :(得分:0)
图片路径应该与event(new App\Events\Closed());
格式相同。 URL
。
yourJSON
http://dev.nsol.sg/projects/sneakers/assets/brand_images/thumb/7a53f87882409c4622a0977d5026038b.jpg
全球宣言:
message = "Success.";
newsurl = "http://dev.nsol.sg/projects/sneakers/assets/brand_images/thumb/";
success = 1;