Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
Ask Question
I am cleaning up some code and trying to put a serverRequest in my NSManagedObject class. The exact same function works perfectly in the UIViewController it was originally written in, however, when I call it in the CoreData object file I get the following Error:
Error Domain=com.alamofire.error.serialization.request Code=-1016 "The `parameters` argument is not valid JSON." UserInfo={NSLocalizedFailureReason=The `parameters` argument is not valid JSON.}
I printed my 'parameters' in the original case as well as the new and they are EXACTLY the same. I am successfully hitting other endpoints I have setup in this CoreData object class, but this one for some reason is failing.
Any ideas?
Successful: uploading question packet ChecklistTABLEVIEW.swift
["answers": ["each": <_TtGCs23_ContiguousArrayStoragePs9AnyObject__ 0x604000c551b0>(
answerString = "";
"assigned_emails" = (
"email@email.com"
"checklist_id" = 186;
questionId = 4274;
rating = "";
"report_time" = "2018-09-13 19:40:21 +0000";
answerString = "";
"assigned_emails" = (
"email@email.com"
"checklist_id" = 186;
questionId = 293112;
rating = "";
"report_time" = "2018-09-13 19:40:21 +0000";
selected = (
, "checklist_id": 186], "user": ["authentication_token": "TOKEN", "email": "email@email.com"], "count": 2]
Unsuccessful: uploading question packet CHECKLIST.swift
["answers": ["each": <_TtGCs23_ContiguousArrayStoragePs9AnyObject__ 0x600000c57ee0>(
answerString = "";
"assigned_emails" = (
"email@email.com"
"checklist_id" = 186;
questionId = 4274;
rating = "";
"report_time" = "2018-09-13 19:40:21 +0000";
answerString = "";
"assigned_emails" = (
"email@email.com"
"checklist_id" = 186;
questionId = 293112;
rating = "";
"report_time" = "2018-09-13 19:40:21 +0000";
selected = (
, "checklist_id": 186], "user": ["authentication_token": "TOKEN", "email": "email@email.com"], "count": 2]
Those parameters are the exact same in the Successful and Unsuccessful cases, they are just called from different files. Why would one get an serialization error from AFNetworking?
I found the problem. I had a date in my parameters and had to convert it to a String.
I used this code to find the specific issue.
if JSONSerialization.isValidJSONObject(params)
if let data = try? JSONSerialization.data(withJSONObject: params, options: [])
print("JSON data object is: \(data)")
let data = try JSONSerialization.data(withJSONObject: params, options: [])
print("JSON data object is: \(data)")
catch let error as NSError
print("no bueno: \(error)")
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.