I am using FBSDK with Xcode 7.2.1 to extract user profile information and use SwiftyJson to process and process json data. After changing the values / deleting some, I want to make a request to send to api with JSON data. But I quickly got stuck in problems with a very bad type.
This is my code to create a mail request:
let headers = [ "Content-Type": "application/json" ] let userProfile = userProfile as? [String : AnyObject] Alamofire.request(.POST, "http://localhost:8888/api/profile", parameters: userProfile, headers: headers, encoding:ParameterEncoding.URL) .response { request, response, data, error in print(userProfile) //This prints nil print(response) //This prints api error for expecting data }
Sorry, I get this error:
Sent from 'JSON' to an unrelated type '[String: AnyObject]' always fails
If I try to send JSON data directly to the API, I get this error:
Cannot convert value of type "JSON" to the expected type of argument "[String: AnyObject]?"
Any help is appreciated. I just want to know how to convert a JSON object to a String AnyObject? without crashing. Or send a Json object as the post / put / patch request data using Swift 2.
xcode swift facebook-ios-sdk
artuc
source share