如何将图像数组从json格式解析为tabelview

《如何将图像数组从json格式解析为tabelview》

你好,我有像下面这样的json数据

{
  "data" : [
    {
      "resolved" : "N\/A",
      "type" : "Internal",
      "notes" : "test",
      "property_id" : "22",
      "regulation_item" : "8",
      "locations" : "Test",
      "id" : "45",
      "boiler_service_date" : "",
      "action" : "Further Investigation \/ Maintenance Required",
      "intervention_required" : "N\/A",
      "regulation_id" : "4",
      "regulation_item_name" : "Floors",
      "contravention" : "27",
      "images" : [
        "http:\/\/christies.buildingcontrolregister.ie\/webservice\/assets\/uploads\/inspection_photo\/img_fzvXhnBwpw1547270966.png"
      ],
      "contraventions_item_name" : "Damaged wooden floors"
    },
    {
      "resolved" : "N\/A",
      "type" : "Internal",
      "notes" : "test",
      "property_id" : "22",
      "regulation_item" : "8",
      "locations" : "Ahmedabad",
      "id" : "47",
      "boiler_service_date" : "",
      "action" : "Maintenance Attention Required",
      "intervention_required" : "N\/A",
      "regulation_id" : "4",
      "regulation_item_name" : "Floors",
      "contravention" : "27",
      "images" : [
        "http:\/\/christies.buildingcontrolregister.ie\/webservice\/assets\/uploads\/inspection_photo\/img_UNQbzzwTaK1547616334.png"
      ],
      "contraventions_item_name" : "Damaged wooden floors"
    },
    {
      "resolved" : "N\/A",
      "type" : "Internal",
      "notes" : "shhsge",
      "property_id" : "22",
      "regulation_item" : "8",
      "locations" : "Shsg",
      "id" : "57",
      "boiler_service_date" : "",
      "action" : "Maintenance Attention Required",
      "intervention_required" : "N\/A",
      "regulation_id" : "4",
      "regulation_item_name" : "Floors",
      "contravention" : "27",
      "images" : [
        "http:\/\/christies.buildingcontrolregister.ie\/webservice\/assets\/uploads\/inspection_photo\/"
      ],
      "contraventions_item_name" : "Damaged wooden floors"
    },
    {
      "resolved" : "N\/A",
      "type" : "Internal",
      "notes" : "ewfewf",
      "property_id" : "22",
      "regulation_item" : "8",
      "locations" : "retested",
      "id" : "58",
      "boiler_service_date" : "",
      "action" : "Maintenance Attention Required",
      "intervention_required" : "N\/A",
      "regulation_id" : "4",
      "regulation_item_name" : "Floors",
      "contravention" : "27",
      "images" : [
        "http:\/\/christies.buildingcontrolregister.ie\/webservice\/assets\/uploads\/inspection_photo\/img_8edaM4H6lZ1548233123.png",
        "http:\/\/christies.buildingcontrolregister.ie\/webservice\/assets\/uploads\/inspection_photo\/img_KhDXUhCHRN1548233123.png",
        "http:\/\/christies.buildingcontrolregister.ie\/webservice\/assets\/uploads\/inspection_photo\/img_zIhztQ2mVD1548233123.png",
        "http:\/\/christies.buildingcontrolregister.ie\/webservice\/assets\/uploads\/inspection_photo\/img_I3RWeD0VKl1548233123.png",
        "http:\/\/christies.buildingcontrolregister.ie\/webservice\/assets\/uploads\/inspection_photo\/img_VuDzsyR5gI1548233123.png"
      ],
      "contraventions_item_name" : "Damaged wooden floors"
    },
    {
      "resolved" : "N\/A",
      "type" : "Internal",
      "notes" : "sadsad",
      "property_id" : "22",
      "regulation_item" : "8",
      "locations" : "dads sad",
      "id" : "59",
      "boiler_service_date" : "",
      "action" : "Maintenance Attention Required",
      "intervention_required" : "N\/A",
      "regulation_id" : "4",
      "regulation_item_name" : "Floors",
      "contravention" : "27",
      "images" : [
        "http:\/\/christies.buildingcontrolregister.ie\/webservice\/assets\/uploads\/inspection_photo\/img_n19NGjRfcH1548233550.png",
        "http:\/\/christies.buildingcontrolregister.ie\/webservice\/assets\/uploads\/inspection_photo\/img_WQn8zZeT0X1548233550.png",
        "http:\/\/christies.buildingcontrolregister.ie\/webservice\/assets\/uploads\/inspection_photo\/img_GYF21A9lMd1548233550.png",
        "http:\/\/christies.buildingcontrolregister.ie\/webservice\/assets\/uploads\/inspection_photo\/img_eaeoXVIPbU1548233550.png",
        "http:\/\/christies.buildingcontrolregister.ie\/webservice\/assets\/uploads\/inspection_photo\/img_w7KTfkTtdT1548233550.png"
      ],
      "contraventions_item_name" : "Damaged wooden floors"
    },
    {
      "resolved" : "N\/A",
      "type" : "Internal",
      "notes" : "sadsad",
      "property_id" : "22",
      "regulation_item" : "8",
      "locations" : "adds",
      "id" : "60",
      "boiler_service_date" : "",
      "action" : "Maintenance Attention Required",
      "intervention_required" : "N\/A",
      "regulation_id" : "4",
      "regulation_item_name" : "Floors",
      "contravention" : "27",
      "images" : [
        "http:\/\/christies.buildingcontrolregister.ie\/webservice\/assets\/uploads\/inspection_photo\/img_fVghhQFhB31548233912.png",
        "http:\/\/christies.buildingcontrolregister.ie\/webservice\/assets\/uploads\/inspection_photo\/img_k3Y5CaQIsj1548233912.png",
        "http:\/\/christies.buildingcontrolregister.ie\/webservice\/assets\/uploads\/inspection_photo\/img_nVhXpintD51548233912.png",
        "http:\/\/christies.buildingcontrolregister.ie\/webservice\/assets\/uploads\/inspection_photo\/img_gS0wahnPzZ1548233912.png",
        "http:\/\/christies.buildingcontrolregister.ie\/webservice\/assets\/uploads\/inspection_photo\/img_TT2RZF2Pnv1548233912.png"
      ],
      "contraventions_item_name" : "Damaged wooden floors"
    },
    {
      "resolved" : "N\/A",
      "type" : "Internal",
      "notes" : "sadsad",
      "property_id" : "22",
      "regulation_item" : "8",
      "locations" : "sad sad",
      "id" : "61",
      "boiler_service_date" : "",
      "action" : "Further Investigation \/ Maintenance Required",
      "intervention_required" : "N\/A",
      "regulation_id" : "4",
      "regulation_item_name" : "Floors",
      "contravention" : "27",
      "images" : [
        "http:\/\/christies.buildingcontrolregister.ie\/webservice\/assets\/uploads\/inspection_photo\/img_iy7hMFz69u1548234019.png",
        "http:\/\/christies.buildingcontrolregister.ie\/webservice\/assets\/uploads\/inspection_photo\/img_799ad8B4aj1548234019.png",
        "http:\/\/christies.buildingcontrolregister.ie\/webservice\/assets\/uploads\/inspection_photo\/img_5HFLk03Fgp1548234019.png",
        "http:\/\/christies.buildingcontrolregister.ie\/webservice\/assets\/uploads\/inspection_photo\/img_9zYgQKVqQ51548234019.png",
        "http:\/\/christies.buildingcontrolregister.ie\/webservice\/assets\/uploads\/inspection_photo\/img_UYf49scKwn1548234019.png"
      ],
      "contraventions_item_name" : "Damaged wooden floors"
    },
    {
      "resolved" : "N\/A",
      "type" : "Internal",
      "notes" : "sdsadas",
      "property_id" : "22",
      "regulation_item" : "8",
      "locations" : "daddy’s sad sad",
      "id" : "62",
      "boiler_service_date" : "",
      "action" : "Further Investigation \/ Maintenance Required",
      "intervention_required" : "N\/A",
      "regulation_id" : "4",
      "regulation_item_name" : "Floors",
      "contravention" : "27",
      "images" : [
        "http:\/\/christies.buildingcontrolregister.ie\/webservice\/assets\/uploads\/inspection_photo\/img_htPOrErbgF1548234575.png",
        "http:\/\/christies.buildingcontrolregister.ie\/webservice\/assets\/uploads\/inspection_photo\/img_Y4ms5mkzgD1548234575.png",
        "http:\/\/christies.buildingcontrolregister.ie\/webservice\/assets\/uploads\/inspection_photo\/img_nuFk2NsfzV1548234575.png",
        "http:\/\/christies.buildingcontrolregister.ie\/webservice\/assets\/uploads\/inspection_photo\/img_IRpxGQb72s1548234575.png",
        "http:\/\/christies.buildingcontrolregister.ie\/webservice\/assets\/uploads\/inspection_photo\/img_N0w9sCwNcM1548234575.png"
      ],
      "contraventions_item_name" : "Damaged wooden floors"
    },
    {
      "resolved" : "N\/A",
      "type" : "Internal",
      "notes" : "sadsa",
      "property_id" : "22",
      "regulation_item" : "8",
      "locations" : "asdsadas",
      "id" : "63",
      "boiler_service_date" : "",
      "action" : "Further Investigation \/ Maintenance Required",
      "intervention_required" : "N\/A",
      "regulation_id" : "4",
      "regulation_item_name" : "Floors",
      "contravention" : "27",
      "images" : [
        "http:\/\/christies.buildingcontrolregister.ie\/webservice\/assets\/uploads\/inspection_photo\/img_jJj0URkS9o1548234685.png",
        "http:\/\/christies.buildingcontrolregister.ie\/webservice\/assets\/uploads\/inspection_photo\/img_GU95bP9bhn1548234685.png",
        "http:\/\/christies.buildingcontrolregister.ie\/webservice\/assets\/uploads\/inspection_photo\/img_Arob8rq0QU1548234685.png",
        "http:\/\/christies.buildingcontrolregister.ie\/webservice\/assets\/uploads\/inspection_photo\/img_79Erayiurr1548234685.png",
        "http:\/\/christies.buildingcontrolregister.ie\/webservice\/assets\/uploads\/inspection_photo\/img_T8m2dxSmI91548234685.png"
      ],
      "contraventions_item_name" : "Damaged wooden floors"
    },
    {
      "resolved" : "",
      "type" : "Internal",
      "notes" : "Test test",
      "property_id" : "22",
      "regulation_item" : "26",
      "locations" : "Kitchen",
      "id" : "11",
      "boiler_service_date" : "0000-00-00",
      "action" : "Maintenance Attention Required",
      "intervention_required" : "",
      "regulation_id" : "6",
      "regulation_item_name" : "Gas",
      "contravention" : "202",
      "images" : [
        "http:\/\/christies.buildingcontrolregister.ie\/webservice\/assets\/uploads\/inspection_photo\/img_j9QNiQ9Sun1548225475.png",
        "http:\/\/christies.buildingcontrolregister.ie\/webservice\/assets\/uploads\/inspection_photo\/img_zVBEjnkZf41548225475.png",
        "http:\/\/christies.buildingcontrolregister.ie\/webservice\/assets\/uploads\/inspection_photo\/img_LTaxAfGTZW1548225475.png",
        "http:\/\/christies.buildingcontrolregister.ie\/webservice\/assets\/uploads\/inspection_photo\/img_Mj5D6otfhX1548225475.png",
        "http:\/\/christies.buildingcontrolregister.ie\/webservice\/assets\/uploads\/inspection_photo\/img_DQTfucDObS1548225475.png"
      ],
      "contraventions_item_name" : "Condition and certs"
    },
    {
      "resolved" : "",
      "type" : "Internal",
      "notes" : "",
      "property_id" : "22",
      "regulation_item" : "35",
      "locations" : "",
      "id" : "6",
      "boiler_service_date" : "",
      "action" : "Maintenance Attention Required",
      "intervention_required" : "N\/A",
      "regulation_id" : "7",
      "regulation_item_name" : "Items",
      "contravention" : "210",
      "images" : [
        "http:\/\/christies.buildingcontrolregister.ie\/webservice\/assets\/uploads\/inspection_photo\/"
      ],
      "contraventions_item_name" : "4 ring hob, oven and grill in good working order"
    },
    {
      "resolved" : "",
      "type" : "Internal",
      "notes" : "test test",
      "property_id" : "22",
      "regulation_item" : "35",
      "locations" : "",
      "id" : "7",
      "boiler_service_date" : "",
      "action" : "Extractor To Be Vented Out \/ Mechanical Fan To Be Installed",
      "intervention_required" : "N\/A",
      "regulation_id" : "7",
      "regulation_item_name" : "Items",
      "contravention" : "210",
      "images" : [
        "http:\/\/christies.buildingcontrolregister.ie\/webservice\/assets\/uploads\/inspection_photo\/img_1Ot5YN8xL11548151400.png"
      ],
      "contraventions_item_name" : "4 ring hob, oven and grill in good working order"
    },
    {
      "resolved" : "",
      "type" : "Internal",
      "notes" : "test test",
      "property_id" : "22",
      "regulation_item" : "35",
      "locations" : "",
      "id" : "8",
      "boiler_service_date" : "",
      "action" : "Extractor To Be Vented Out \/ Mechanical Fan To Be Installed",
      "intervention_required" : "N\/A",
      "regulation_id" : "7",
      "regulation_item_name" : "Items",
      "contravention" : "210",
      "images" : [
        "http:\/\/christies.buildingcontrolregister.ie\/webservice\/assets\/uploads\/inspection_photo\/img_9vhD62hRcp1548151402.png"
      ],
      "contraventions_item_name" : "4 ring hob, oven and grill in good working order"
    },
    {
      "resolved" : "",
      "type" : "Internal",
      "notes" : "Test Test",
      "property_id" : "22",
      "regulation_item" : "35",
      "locations" : "",
      "id" : "9",
      "boiler_service_date" : "",
      "action" : "Maintenance Attention Required",
      "intervention_required" : "N\/A",
      "regulation_id" : "7",
      "regulation_item_name" : "Items",
      "contravention" : "210",
      "images" : [
        "http:\/\/christies.buildingcontrolregister.ie\/webservice\/assets\/uploads\/inspection_photo\/img_SbrrQxWl2A1548151619.png",
        "http:\/\/christies.buildingcontrolregister.ie\/webservice\/assets\/uploads\/inspection_photo\/img_ly1adD9T3C1548151620.png",
        "http:\/\/christies.buildingcontrolregister.ie\/webservice\/assets\/uploads\/inspection_photo\/img_qVup3MTUHh1548151620.png",
        "http:\/\/christies.buildingcontrolregister.ie\/webservice\/assets\/uploads\/inspection_photo\/img_4Asw2j3YF61548151620.png",
        "http:\/\/christies.buildingcontrolregister.ie\/webservice\/assets\/uploads\/inspection_photo\/img_y0FAbTekMh1548151620.png"
      ],
      "contraventions_item_name" : "4 ring hob, oven and grill in good working order"
    }
  ],
  "total_count" : "1",
  "success" : "1",
  "message" : "Previous inspection list."
}

形成这个数据我得到数据数组但不能在tableview上显示,我也无法理解如何获取图像数组形式,这里的数据是我的填充我的tableview的代码

func PreviousInspeList(){
    let preferences = UserDefaults.standard
    let uid = "u_id"
    let acTkn = "acc_tkn"

    let u_ID = preferences.object(forKey: uid)
    let A_Token = preferences.object(forKey: acTkn)

    let params = ["user_id": u_ID!, "access_token": A_Token!,"property_id": propertyID!]
    print(params)
    SVProgressHUD.show()
    Alamofire.request(previousinspectionslist, method: .post, parameters: params).responseJSON(completionHandler: {(response) in
        switch response.result{
        case.success(let value):
            let json  = JSON(value)
            print(json)
            let data = json["data"]
            data.array?.forEach({ (iList) in
                let inspList = PreviousInspListModel(resolved: iList["resolved"].stringValue, type: iList["type"].stringValue, notes: iList["notes"].stringValue, property_id: iList["property_id"].stringValue, regulation_item: iList["regulation_item"].stringValue, locations: iList["locations"].stringValue, id: iList["id"].stringValue, boiler_service_date: iList["boiler_service_date"].stringValue, action: iList["action"].stringValue, intervention_required: iList["intervention_required"].stringValue, regulation_id: iList["regulation_id"].stringValue, regulation_item_name: iList["regulation_item_name"].stringValue, contravention: iList["contravention"].stringValue, contraventions_item_name: iList["contraventions_item_name"].stringValue)
                self.preInspData.append(inspList)
            })
            self.tblListView.reloadData()

            SVProgressHUD.dismiss()
        case.failure(let error):
            print(error.localizedDescription)
        }

    })
}

这是我的模特课

struct PreviousInspListModel {
    var resolved: String
    var type: String
    var notes: String
    var property_id: String
    var regulation_item: String
    var locations: String
    var id: String
    var boiler_service_date: String
    var action: String
    var intervention_required: String
    var regulation_id: String
    var regulation_item_name: String
    var contravention: String
    var contraventions_item_name: String
}

我只是想告诉我为什么我的数据不会填充在tableview上以及如何获取图像数组并在tableview上显示请帮我这个

最佳答案 在UITableViewCell中添加UICollectionView以显示所有图像.并使用您的Images Array填充UICollectionView.找到在UITableView Cell中添加UICollectionView的好教程

https://ashfurrow.com/blog/putting-a-uicollectionview-in-a-uitableviewcell-in-swift/

struct PreviousInspListModel {
    var resolved: String
    var type: String
    var notes: String
    var property_id: String
    var regulation_item: String
    var locations: String
    var id: String
    var boiler_service_date: String
    var action: String
    var intervention_required: String
    var regulation_id: String
    var regulation_item_name: String
    var contravention: String
    var contraventions_item_name: String
    var imageArray: [String]!
}

在你的循环中:

data.array?.forEach({ (iList) in
                let inspList = PreviousInspListModel(resolved: iList["resolved"].stringValue, type: iList["type"].stringValue, notes: iList["notes"].stringValue, property_id: iList["property_id"].stringValue, regulation_item: iList["regulation_item"].stringValue, locations: iList["locations"].stringValue, id: iList["id"].stringValue, boiler_service_date: iList["boiler_service_date"].stringValue, action: iList["action"].stringValue, intervention_required: iList["intervention_required"].stringValue, regulation_id: iList["regulation_id"].stringValue, regulation_item_name: iList["regulation_item_name"].stringValue, contravention: iList["contravention"].stringValue, contraventions_item_name: iList["contraventions_item_name"].stringValue, imageArray: iList["images"].arrayObject as? [String])
                self.preInspData.append(inspList)
            })
点赞