在nsmutabledictionary中保存响应? swift 3.0

时间:2016-12-01 10:48:06

标签: ios swift3 alamofire

我在Alamofire 4.0中获得回复的代码

Alamofire.request(webpath).responseJSON
    {
        response in

        //here I want to store response in nsmutabledictionary
    }

在该响应中,我有Data对象,其中包含如下数据

{"Success":"True","Data":[{"Id":"4","Name":"xyz"}]

我想在NSMutableArray中保存该数据对象,以便在UITableview

中显示

1 个答案:

答案 0 :(得分:1)

您可以从此Dictionary响应中获得结果Alamofire

Alamofire.request(webpath).responseJSON
{
    response in

    switch(response.result) {
    case .success(_):
        if let dic = response.result.value as? [String: Any], 
           let array = dic["Data"] as? [[String: Any]] {
            print(array)
        }
    case .failure(_):
        print(response.result.error)
    }
}

注意:使用Swift原生DictionaryArray代替NSDictionaryNSArray

相关问题