Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Parsing JSON Using Codable Parsing Different JSON Structures Recap: Parsing Different JSON Structures

let post = try! decoder.decode([String: Post].self, from: json) works in swift playground but fails in treehouse test.

the below json and struct can be accessed fine and without needing to write custom init (as per the question) with:

let post = try! decoder.decode([String: Post].self, from: json) print(post)

but the treehouse test/quiz thing will not accept as correct answer. Maybe I miss something or the question needs to be clearer??

let json = """ { "result": { "title": "My First Blog Post", "author": "Pasan Premaratne", "date": "April 16, 2018" } } """.data(using: .utf8)!

struct Post: Codable { let title: String let author: String let date: String }

let decoder = JSONDecoder()

1 Answer

[String: [Status]].self

Your answer is 100% correct but the quiz is missing the comma. Just remove the comma and youll go through, they meant to put the comma there for you but they forgot.

i hope you get it