Alamofire invalid value around character 0
I also faced same issue. I tried responseString
instead of responseJSON
and it worked. I guess this is a bug in Alamofire
with using it with django
.
Swift - Alamofire Invalid value around character 0.
Ok, finally I solved the problem
Here's new request :
Alamofire.request(url!, method: .post,encoding : JSONEncoding.default, headers: headers, parameters: params).responseJSON { (response) in
print(response)
}
With Headers :
let headers = [
"Content-Type": "application/json"
]
Alamofire .post api error: Code=3840 Invalid value around character 1
Replace responseJSON
with responseString
.
You need to convert the string for values. Can you update the string in your question?
You can use this function to convert response string into JSON:
func convertToDictionary(text: String) -> [String: Any]? {
if let data = text.data(using: .utf8) {
do {
return try JSONSerialization.jsonObject(with: data, options: []) as? [String: Any]
} catch {
print(error.localizedDescription)
}
}
return nil
}
String: let str = "{\"name\":\"James\"}"
USAGE: let dict = convertToDictionary(text: str)
Related Topics
Why Maskstobounds = Yes Prevents Calayer Shadow
View with Continuous Scroll; Both Horizontal and Vertical
iOS 8 Swift - Tableview with Embedded Collectionview
Monotouch/Wcf: How to Consume the Wcf Service Without Svcutil
How to Save a Uicolor with Userdefaults
Xcode Myprojectname-Bridging-Header.H Does Not Exist
How to Send a Silent Push Notification Payload
Core Audio Offline Rendering Genericoutput
Current Week Start and End Date
How to Fetch All Contacts Record in iOS 9 Using Contacts Framework
"Untrusted App Developer" Message When Installing Enterprise iOS Application
Autolayout + Rtl + Uilabel Text Alignment
Optional Chaining in Swift Closure Where Return Type Has to Be Void
How to Create P12 Certificate for iOS Distribution