Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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