ios - 如何使用 Alamofire 快速调用 web 服务?

标签 ios swift

<分区>

我对 swift 语言比较陌生。谁能解释一下如何像我们在 Objective-c 语言中那样在 nsmutableArray 或 nsmutableDictionary 中调用服务和存储。

最佳答案

试试这个示例代码

声明数组

var textArr = [String]()
var nameArr = [String]()

在swift3中使用alamofire

      Alamofire.request(url, parameters: ["user":"any username"
            ,"media_id":"anyid"]).responseJSON { response in

                if response.result.isSuccess == true
                {
                    if let value = response.result.value {
                        let json = JSON(value)
                        print(self.json)

                       let comment_arr = self.json["comment_arr"]
                       for (index, _): (String, JSON) in comment_arr {
                                let i : Int = Int(index)!

                                let name = comment_arr[i]["user"].stringValue
                                let text = comment_arr[i]["text"].stringValue

                                self.nameArr.append(name)
                                self.textArr.append(text)
                            }
                            self.tableView.reloadData()
                            self.loadingNotification.hide(animated: true)
                        }
                }
                else
                {
                }
        }

希望对你有用!!!

关于ios - 如何使用 Alamofire 快速调用 web 服务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39849012/

相关文章:

ios - swift ios 中的坐标系错误

ios - 将 base64URL 解码为 base64——Swift

ios - 传递给不同 Controller 时 AVPlayer 持续时间会发生变化

cocoa - Swift - 选择文件时发出警告(Cocoa)

swift - 函数在完成 block 完成之前返回

arrays - 解析将字符串添加到数组 swift

ios - "Expression implicitly coerced"警告是什么意思?

ios - 按钮约束 Swift

iphone - Plist 文件转换 xml 文件在 iphone 中?

iOS 联系人未显示在桌面 View 中