Question: I am working on a project where I am getting a dictionary of an array which again containt the dictionary

My Json Response is 

```
{
"code": 200,
"status": "OK",
"success": "true",
"message": "success",
"data": {
"vehicletypeData": [
  {
    "vehicle_type_id": "1",
    "vehicle_type": "Any"
    },
    {
      "vehicle_type_id": "11",
      "vehicle_type": "Bike"
    }
   ]
  }
 }

```

And I am parsing the data like

```
        if response.success {
            let resObj = response.responseObject as! Dictionary<String, Any>
            let catArray = resObj["data"] as! Dictionary<String,Array<Dictionary<String,Any>>>   // Crashes here
            let vehicleData = catArray["vehicletypeData"] as! Array<Dictionary<String, Any>>

            for vehicle in vehicleData {
                self.jobCategories.append(PreJobVehicleData.mj_object(withKeyValues: vehicle))
            }
        }

```

I am trying to parse it in my model

Here I am getting an error like
 - Could not cast value of type '\_\_NSArrayM' (0x109b82e00) to 'NSDictionary' (0x109b832d8)

Any help will be Thankful.

Answer: 
Don't say 

```
 resObj["data"] as! Dictionary<String,Array<Dictionary<String,Any>>>

```

That's too specific. Just say

```
 resObj["data"] as! [String:Any]

```

*You* know that when you get something by key out of that dictionary, it will be an array, but you can literally cross that bridge when you come to it.

The same rule applies to your other casts. Just cast to Swift dictionary or array using the broadest simplest possible type.

(Note that all this will be solved in Swift 4, where you can build a knowledge of the JSON structure right into your fetch.)
As you are parsing the nodes separately anyway avoid to cast to (more than two levels) nested types.

According to the error message the value for key `data` seems to be an array (`Array<Dictionary<String, Any>>`)

```
if response.success {
    let resObj = response.responseObject as! Dictionary<String, Any>
    let dataArray = resObj["data"] as! Array<Dictionary<String, Any>>

...

```

That implies however that the JSON output is wrong and I have no idea what's next...