title: Type 'AreaData' does not conform to protocol 'Encodable'
body: <p>When I make a model for my JSON file, I get these two errors. </p>
  
  <p>1) I got the conform error in AreaData struct</p>
  
  <p>2) "<code>AnyObject</code> cannot be used as a type conforming to protocol <code>Decodable</code> because <code>Decodable</code> has static requirements" error in initialiser. </p>
  
  <p>I have tried several ways but I cannot find the correct solution. How can I make a proper model for this nested/complex JSON?</p>
  
  <p>Here is my JSON file. This data is nested</p>
  
  <pre><code>[
      {
          "ID": "01",
          "Name": "Area 01",
          "parentId": null,
          "sublevel": [
              {
                  "ID": "01-01",
                  "Name": "Building 01",
                  "On": "",
                  "Off": "",
                  "parentId": "01",
                  "sublevel": [
                      {
                          "ID": "01-01-01",
                          "Name": "Flat 01",
                          "On": "",
                          "Off": "",
                          "parentId": "01-01",
                          "sublevel": []
                      }
                  ]
              },
              {
                  "ID": "01-02",
                  "Name": "Building 02",
                  "On": "01",
                  "Off": "03",
                  "parentId": "01",
                  "sublevel": [
                      {
                          "ID": "01-02-01",
                          "Name": "Flat 01",
                          "On": "",
                          "Off": "",
                          "parentId": "01-02",
                          "sublevel": []
                      },
                      {
                          "ID": "01-02-02",
                          "Name": "Flat 02",
                          "On": "01",
                          "Off": "02",
                          "parentId": "01-02",
                          "sublevel": []
                      },
                      {
                          "ID": "01-02-03",
                          "Name": "Flat 03",
                          "On": "02",
                          "Off": "12",
                          "parentId": "01-02",
                          "sublevel": [
                              {
                                  "ID": "01-02-03-01",
                                  "Name": "Room 01",
                                  "On": "",
                                  "Off": "",
                                  "parentId": "01-02-03",
                                  "sublevel": []
                              },
                              {
                                  "ID": "01-02-03-02",
                                  "Name": "Room 02",
                                  "On": "",
                                  "Off": "",
                                  "parentId": "01-02-03",
                                  "sublevel": []
                              },
                              {
                                  "ID": "01-02-03-03",
                                  "Name": "Room 03",
                                  "On": "02",
                                  "Off": "03",
                                  "parentId": "01-02-03",
                                  "sublevel": []
                              },
                              {
                                  "ID": "01-02-03-04",
                                  "Name": "Room 04",
                                  "On": "",
                                  "Off": "",
                                  "parentId": "01-02-03",
                                  "sublevel": []
                              },
                              {
                                  "ID": "01-02-03-05",
                                  "Name": "Room 05",
                                  "On": "01",
                                  "Off": "",
                                  "parentId": "01-02-03",
                                  "sublevel": []
                              }
                          ]
                      },
                      {
                          "ID": "01-02-04",
                          "Name": "Flat 04",
                          "On": "12",
                          "Off": "03",
                          "parentId": "01-02",
                          "sublevel": []
                      },
                      {
                          "ID": "01-02-05",
                          "Name": "Flat 05",
                          "On": "02",
                          "Off": "",
                          "parentId": "01-02",
                          "sublevel": []
                      }
                  ]
              },
              {
                  "ID": "01-03",
                  "Name": "Building 03",
                  "On": "02",
                  "Off": "01",
                  "parentId": "01",
                  "sublevel": []
              },
              {
                  "ID": "01-04",
                  "Name": "Building 04",
                  "On": "",
                  "Off": "",
                  "parentId": "01",
                  "sublevel": []
              }
          ]
      }
  ]
  </code></pre>
  
  <p>And this is my model class</p>
  
  <pre><code>import Foundation
  struct AreaData : Codable {
  
      let iD : String?
      let name : String?
      let parentId : AnyObject?
      let sublevel : [Sublevel]?
  
      enum CodingKeys: String, CodingKey {
          case iD = "ID"
          case name = "Name"
          case parentId = "parentId"
          case sublevel = "sublevel"
      }
  
      init(from decoder: Decoder) throws {
          let values = try decoder.container(keyedBy: CodingKeys.self)
          iD = try values.decodeIfPresent(String.self, forKey: .iD)
          name = try values.decodeIfPresent(String.self, forKey: .name)
          parentId = try values.decodeIfPresent(AnyObject.self, forKey: .parentId)
          sublevel = try values.decodeIfPresent([Sublevel].self, forKey: .sublevel)
      }
  
  }
  
  struct Sublevel : Codable {
  
      let on : String?
      let iD : String?
      let name : String?
      let off : String?
      let parentId : String?
      let sublevel : [Sublevel]?
  
      enum CodingKeys: String, CodingKey {
          case on = "On"
          case iD = "ID"
          case name = "Name"
          case off = "Off"
          case parentId = "parentId"
          case sublevel = "sublevel"
      }
  
      init(from decoder: Decoder) throws {
          let values = try decoder.container(keyedBy: CodingKeys.self)
          on = try values.decodeIfPresent(String.self, forKey: .on)
          iD = try values.decodeIfPresent(String.self, forKey: .iD)
          name = try values.decodeIfPresent(String.self, forKey: .name)
          off = try values.decodeIfPresent(String.self, forKey: .off)
          parentId = try values.decodeIfPresent(String.self, forKey: .parentId)
          sublevel = try values.decodeIfPresent([Sublevel].self, forKey: .sublevel)
      }
  
  }
  </code></pre>