我如何获得响应数据?

时间:2015-06-26 05:39:43

标签: ios swift response

我不知道如何使用响应数据。我尝试将它添加到字典中但是当我打印它时我得到:

Swift.LazyForwardCollection,Swift.AnyObject>>

let manager = AFHTTPRequestOperationManager()

    var params : Dictionary = ["username": user, "password": pass, "phone": numb]

    manager.POST(

        "http://happybakuapi.com/tehmin/api_evelazim/signup.php",

        parameters: params,

        success: { (operation: AFHTTPRequestOperation!, responseObject: AnyObject!) in

            println("JSON: " + responseObject.description)

            var jsonResult = responseObject as! Dictionary<String, AnyObject>



            println(jsonResult.values)

        },

        failure: { (operation: AFHTTPRequestOperation!, error: NSError!) in

            println("Error: " + error.localizedDescription)

        }

    )

1 个答案:

答案 0 :(得分:1)

你可以使用字典的响应如下。

let manager = AFHTTPRequestOperationManager()

        var params : Dictionary = ["username":"Aplle", "password": "asdsad", "phone": "919909999099"]

        manager.POST("http://happybakuapi.com/tehmin/api_evelazim/signup.php",parameters: params,

            success: { (operation: AFHTTPRequestOperation!, responseObject: AnyObject!) in


                println(responseObject)

                println(responseObject.objectForKey("response"))

                println(responseObject.objectForKey("error_type"))

                println(responseObject.objectForKey("user_exist"))

            },

            failure: { (operation: AFHTTPRequestOperation!, error: NSError!) in

                println("Error: " + error.localizedDescription)

            }

        )

回复词典:

{
    "error_type" = "user isset in database";
    response = false;
    "user_exist" = 1;
}