【问题标题】:Swift 3 Alamofire JSON responseSwift 3 Alamofire JSON 响应
【发布时间】:2016-12-24 10:31:54
【问题描述】:

我已经到了获得响应的阶段,并且能够在 Xcode 中将数据打印到控制台中,但我不知道如何对数据进行排序。例如,我有 4 种类型被发送回客户端,我希望能够将它们设置为变量以在标签或其他元素中使用。

Alamofire.request(url, method: .post, encoding:     JSONEncoding.default)
        .responseJSON { response in
            print(response)
        }

【问题讨论】:

  • print(response.result) 打印此结果以将结果发送回客户

标签: json swift alamofire


【解决方案1】:

你真的应该用谷歌搜索这个。您可以找到已被多次询问的类似问题。

这是一个例子

        var name : String?
        var age : Int?
        var stupid : Bool?
        var ageString : String?


    Alamofire.request(url, method: .post, encoding:     JSONEncoding.default)
            .responseJSON { response in
               if response != nil {
                  name = response.name
                  age = response.age
                  stupid = response.stupid

               }
            }
//    If you want a response to be converted and stored, you can do this

             ageString = String(response.age)

//    To use this value on a label 
           nameLabel.text = name
           ageLabel.text = ageString

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-07-22
    • 1970-01-01
    • 1970-01-01
    • 2021-09-17
    • 1970-01-01
    • 1970-01-01
    • 2020-03-28
    相关资源
    最近更新 更多