Preparing JSON for iOS Decode
Fullstack Social iOS NodeJS REST
Now that we're logged into the system, we'll want to ask the server for the post objects that belong to our user. This is rather simple using the req.wantsJSON check from with SailsMVC. This mechanism is quite common amongst backend frameworks and works for requests asking for "application/json" content from with headers. Once we get data back in JSON format, it's only a matter of setting up our JSONDecoder and models objects to finish up the task. We'll have our list of post objects rendered out in iOS by the end of the lesson.

Comments (7)
waynefj40
4 years ago
Source files for this episode? :D
Brian Voong
4 years ago
dblockmoreau
4 years ago
Hey Brian, Im getting the following code.. typeMismatch(Swift.String, Swift.DecodingError.Context(codingPath: [_JSONKey(stringValue: "Index 0", intValue: 0), CodingKeys(stringValue: "id", intValue: nil)], debugDescription: "Expected to decode String but found a number instead.", underlyingError: nil)) so it's saying it found an int instead of string? but I cant really figure out from where.. Sorry for the dumb question lol
Brian Voong
4 years ago
pdefilippi
4 years ago
Hey Bryan, No matter what I do I keep getting an Unauthorized in Postman. I have the cookie included. Is there anything else I should include when configuring postman? I also have tried with x-www-form-urlencoded checked and unchecked under the body tab.
Brian Voong
4 years ago
pdefilippi
4 years ago
Hey Bryan, Fair enough. Maybe you can do a video at the end that thoroughly walks us through using Postman. I have yet to find a good one.
Lazaro Ambrosio
2 years ago
Same here as well. I am getting 401 Unauthorized. I'll skip this step.
AlfieLBTA
3 years ago
Hey Brian, why the model "id's" are of type "String" and not "Int"?
AlfieLBTA
3 years ago
NVM, just realized is due to the fact that you are using a MongoDB id and not a SQL one =).
Setwork44
3 years ago
Brian please help again my login button is not working
Setwork44
3 years ago
Still getting this error "[LayoutConstraints] Unable to simultaneously satisfy constraints." does anyone know what could be the issue here? I changed the form view and added (frame: UISreen.main.bounds) but its still not allowing me to log in...
JMan
2 years ago
Hey Brian, I'm getting this error Failed to fetch posts: responseValidationFailed(reason: Alamofire.AFError.ResponseValidationFailureReason.unacceptableStatusCode(code: 401)) Sent req to server...lets see what we have dataCorrupted(Swift.DecodingError.Context(codingPath: [], debugDescription: "The given data was not valid JSON.", underlyingError: Optional(Error Domain=NSCocoaErrorDomain Code=3840 "Invalid value around character 0." UserInfo={NSDebugDescription=Invalid value around character 0.}))) Any Ideas on what might be wrong?
JMan
2 years ago
Nvm, Solved it! Great Course!
weeren
2 years ago
JMan, I am having the same problem as well .May I know your solution to it?
HELP & SUPPORT