从api获取json数据后,就会在tableview问题中填充

时间:2019-07-10 03:51:55

标签: ios json swift uitableview

PLEASE check

您好,我问过这里如何从json获取号码列表,这是问题和解决方案的链接

问题 issue while fetch data from nested json array

我的答案 https://stackoverflow.com/a/56946750/10804348

所以我要获取数字列表的数据,但如何在表格视图中填充它们

让我告诉我我的代码

func messageListAPI(){

    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!,"twilio_number": "+13344313181"]
    // print(params)
    Alamofire.request(messagelist, method: .post, parameters: params).responseJSON(completionHandler: {(response) in
        switch response.result{
        case.success(let value):
            print(value)
            guard let data = response.data else { return }
            do {
                let decoder = JSONDecoder()
                let response = try decoder.decode(ResponseModel.self, from: data)
                let numberList = response.messageList.compactMap({ $0.keys })
                print("my numberList -> \(numberList)")   // HERE I am getting data like below
                dataToPopulate.append(numberList) //Here i am getting error
            } catch let error {
                print(error)

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

    })
}

printing numberList时,我得到如下列表

my numberList -> [Dictionary.Keys(["+919722552298"]), Dictionary.Keys(["+61459036405"]), Dictionary.Keys(["+918733009842"])]

任何人都可以告诉我如何在表格视图中填充numberList数据

我创建了一个var dataToPopulate = [[String: [MessageList]]]()类型的字典

,然后尝试附加numberList数据,但是无法附加我已经尝试过了

0 个答案:

没有答案