如何在swift 3.0中获得Json Response?

时间:2016-11-22 07:03:43

标签: json swift3 alamofire xcode8

我在XCode 8中使用不同格式的JSON响应,因为它出现在XCode 7.3中

因为我的应用程序停止响应。我正在分享我的回复截图。

这是我正在使用的代码

func MobileNumber(_ notification : Notification){
        activityIndicator.stopAnimating()
        if let notificationDict = (notification as NSNotification).userInfo{
            print(notificationDict)
            if let dataDict = notificationDict["Data"] as? NSDictionary{
                print(dataDict)
                if let status = dataDict["response"] as? Int{
                    switch status{
                    case 1:
                        if let data = dataDict["data"] as? NSDictionary{
                            if let mobileNumber = data["phone"] as? String{
                                UserDefaults.standard.set(mobileNumber, forKey: DefaultsKey.phoneNumber.rawValue)
                                print(mobileNumber)
                            }
                            UpdateFrame1()
                        }

JSON响应:

Data]: 243 bytes
[Result]: SUCCESS: {
    data =     {
        "__v" = 0;
        "_id" = 5833e131de2fe2342b0d0410;
        code = "<null>";
        "created_at" = "2016-11-22T06:09:53.097Z";
        "expiry_date" = "2016-11-22T06:09:53.097Z";
        phone = 9********;
        status = active;
    };
    message = "Resending your unused auth code";
    response = 1;
}
[Timeline]: Timeline: { "Request Start Time": 501493300.746, "Initial Response Time": 501493302.862, "Request Completed Time": 501493302.868, "Serialization Completed Time": 501493302.872, "Latency": 2.116 secs, "Request Duration": 2.122 secs, "Serialization Duration": 0.003 secs, "Total Duration": 2.126 secs }

1 个答案:

答案 0 :(得分:0)

试试这个: -

s