Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decoding JSON to Swift Model Not Root Level #17

Closed
ahmadabudawod opened this issue Apr 20, 2020 · 3 comments
Closed

Decoding JSON to Swift Model Not Root Level #17

ahmadabudawod opened this issue Apr 20, 2020 · 3 comments

Comments

@ahmadabudawod
Copy link

I have one case related to decoding JSON, while I have created a model based on the JSON structure which is dictionary but the data that I need is in nested fields with an array type, not at the root level.

Based on the architecture of your application how I can go directly to nested filed to get array because I got the below error once I am trying to parse the actual JSON retrieved from API.

Error:
typeMismatch(Swift.Array, Swift.DecodingError.Context(codingPath: [], debugDescription: "Expected to decode Array but found a dictionary instead.", underlyingError: nil))

@nalexn
Copy link
Owner

nalexn commented Apr 20, 2020

Hey, I'd be able to help if you provide a concrete json example and the data structures you currently use for parsing. This might be helpful as well: encoding and decoding custom types

@ahmadabudawod
Copy link
Author

Thanks @nalexn for your quick response, I have found how I can go to nested items from web-repository to be mapped with data structure at interactors.
Below the line code that I have updated in your great sample app.

.sinkToLoadable { weakAppState?[\.userData.items] = $0.map { (**$0.records ?? []**) }}

@nalexn
Copy link
Owner

nalexn commented Apr 27, 2020

Great! Feel free to open a new issue if something else pops up

@nalexn nalexn closed this as completed Apr 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants