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

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