Type 'Any' doesn't conform to protocol 'Sequence'

10,123

Specify the type of jsonDataArray to directly [[String: Any]] and try like this.

if let jsonDataArray = try? JSONSerialization.jsonObject(with: data!, options: []) as? [[String: Any]] {
     for eachData in jsonDataArray {
         let eachStop = busStops(jsonDataDictiony: jsonDataDictionary)
     }
}
Share:
10,123
Ronald Aja
Author by

Ronald Aja

Updated on June 05, 2022

Comments

  • Ronald Aja
    Ronald Aja almost 2 years

    I am having troubles in my codes, when trying to parse JSON data (each data of an array, like how it should be done) and trying to set up the for in loop, the error comes out. Here's my code

    if let jsonDataArray = try? JSONSerialization.jsonObject(with: data!, options: [])
    {
    
        print(jsonDataArray)
    
        var allStops = [busStops]()
    
        for eachData in jsonDataArray
                        ^
        //this is where the error is located 
    
        {
    
            if let jsonDataDictionary = eachData as? [String : AnyObject]
            {
    
                let eachStop = busStops(jsonDataDictiony: jsonDataDictionary)
    
            }
    
        }
    
    }
    
  • Rajasekhar Pasupuleti
    Rajasekhar Pasupuleti about 6 years
    Thanks, It is worked for me. if let corners = barcodeMetadataObject.corners as? [[String: Any]] { }