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

Bastian Petersson
Bastian Petersson
9,164 Points

Given the following JSON and Codable conforming type, fill in the blanks

I really don't know how to complete this challenge. Please help :D

 let json = """
 {
   "results": [
     {
       "code": 200
     },
     {
       "code": 401
     },
     {
       "code": 320
     }
   ]
 }
 """.data(using: .utf8)!

 struct Status: Codable {
     let code: Int
 }

 let decoder = JSONDecoder()

 let statuses = try! decoder.decode([String:[[String: Status]]].self, from: json)

1 Answer

Jialong Zhang
Jialong Zhang
9,821 Points

let statuses = try! decoder.decode([String: [Status]].self, from: json) This Challenge is missing comma. Just ignore the comma, answer is: [String: [Status]].self