title: How to fix "Expected to decode Dictionary<String, Any> but found an array instead"?
body: <p>I am trying to decode JSON like this.</p>
  
  <p>this is my data model</p>
  
  <pre><code>struct ResponseData: Decodable {
          var AppointMentStatusId:Int!
          var FromTime:String!
          var ToTime:String!
          var AppointmentDate: String!
          var AppointMentStatus:String!
          var DoctorFirstName:String!
          var AppointmentId:Int!
          var Rating:Float
          var DoctorImage:String
  
  
          enum CodingKeys: String, CodingKey {
              case AppointMentStatusId
              case FromTime
              case ToTime
              case AppointmentDate
              case AppointMentStatus
              case DoctorFirstName
              case AppointmentId
              case Rating
              case DoctorImage
          }
  }
  </code></pre>
  
  <p>I also set init in ResponseData</p>
  
  <pre><code> struct Response:Decodable {
          var Code:Int!
          var Data2:String?
          var Message:String!
          var NoOfItems:String!
          var Status:Bool!
          var Data:[ResponseData]
  
          enum CodingKeys: String, CodingKey {
              case Code
              case Data2
              case Message
              case NoOfItems
              case Status
              case Data
          }
  
          init(from decoder: Decoder) throws {
              let container = try decoder.container(keyedBy: CodingKeys.self)
  </code></pre>
  
  <p>I have got problem with this code</p>
  
  <pre><code> if let app = try container.decodeIfPresent([ResponseData].self, forKey: .Data) {// Problem is here
                  self.Data = app
              }else{
                  self.Data = []
              }
  
              if let code = try container.decodeIfPresent(Int.self, forKey: .Code) {
                  self.Code = code
              }else{
                  self.Code = 0
              }
  </code></pre>
  
  <p>I have set try for all keys</p>
  
  <p>I am trying to handle the nil value of Data key.
  When I got Data key is nil it's working fine 
  When I got data in Data key it's show error.</p>
  
  <pre><code>typeMismatch(Swift.Dictionary&lt;Swift.String, Any&gt;, Swift.DecodingError.Context(codingPath: [CodingKeys(stringValue: "Data", intValue: nil)], debugDescription: "Expected to decode Dictionary&lt;String, Any&gt; but found an array instead.", underlyingError: nil))
  </code></pre>
  
  <p>It's my JSON Data</p>
  
  <pre><code>{
      "Code": 0,
      "Status": true,
      "Message": "Success",
      "Data": [
          {
              "PatientUserID": 196,
              "FirstName": "gaurav",
              "MiddleName": "",
              "LastName": "",
              "PatientName": "gaurav ",
              "MobileNo": "8585959585",
              "EmailId": "gaurav.sainini@gmail.com",
              "DOB": "2005-06-14T00:00:00",
              "Gender": "Male",
              "RegistrationId": 121,
              "VisitId": null,
              "FromTime": "8:00AM",
              "ToTime": "8:15AM",
              "AppointmentDateForComparison": "2019-07-20T00:00:00",
              "AppointmentDate": "20-07-2019",
              "AppointMentStatusId": 1233,
              "AppointMentStatus": "Booked",
              "DoctorId": 1,
              "DoctorFirstName": "Dr.Doctor",
              "Rating": 3.5,
              "DoctorImage": "http://23.88.103.43:83/Assets/Icons/DoctorIcon/DefaultMale.png",
              "AppointmentId": 250,
              "MemberID": 126
          }
      ],
      "Data2": null,
      "NoOfItems": null
  }
  </code></pre>
  
  <p>Please help me on how to handle this error?
  Thanks</p>