2016-12-24 107 views
-2

我已經得到了在那裏我得到迴應和我能夠將數據打印到在Xcode控制檯中的階段,但我無法弄清楚如何對數據進行排序。例如,我有4種類型被髮送回客戶端,我希望能夠將它們設置爲標籤或其他元素中使用的變量。斯威夫特3 Alamofire JSON響應

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

打印(response.result)打印你的結果發送回客戶端 –

回答

0

你應該真的谷歌這個。您可以找到多次詢問過的類似問題。

繼承人就是一個例子

 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