Type 'Any' has no subscript members error on Alamofire 4.0
Try below code:
Alamofire.request(url!, method: .get, parameters: nil, encoding: JSONEncoding.default, headers: nil).responseJSON { response in
switch(response.result) {
case .success(_):
if let JSON = response.result.value as! [[String : Any]]!{
print("JSON: \(JSON)")
let dic = JSON[0] as [String:AnyObject]!
print("TitularEmail : ",dic?["TitularEmail"])
}
break
case .failure(_):
print("There is an error")
break
}
}
Type Any has no subscript members / Swift 3
You need to specify the type of your JSON
object to [String : Any]
.
if let JSON = response.result.value as? [String : Any] {
if let items = JSON["items"] as? [[String : Any]] {
for video in items {
//Here use video["snippet.resourceId.videoId"] instead of value for key
}
}
}
Note : In swift it is batter if you use swift generic Array and dictionary objects instead of NSArray
& NSDictionary
.
swift 3 Type 'Any' has no subscript members?
Typecast response as:
if let json = response.result.value as? [String:AnyObject]{..}
Alamofire 5: Value of type 'ResultData, AFError' has no member 'value'
You have to extract the result
value as below,
func getCurrentUser(_ completion: @escaping (SomeRequest?) -> ()) {
let path = "/somePath"
AF.request("\(url)\(path)").responseData { response in
switch response.result {
case .success(let value):
print(String(data: value, encoding: .utf8)!)
completion(try? SomeRequest(protobuf: value))
case .failure(let error):
print(error)
completion(nil)
}
}
}
Related Topics
Swiftui Show/Hide Title Issues with Navigationbar
iOS Name of This Way of Building and Returning an Object in Objective-C
iOS 9 Objective-C Screen Size Issues
Timestamp Function That Has Been Working Reliably Just Caused Exc_Bad_Instruction
Returning Object from Callback in Swift
Strange Constraints Behaviour on iPad
Uilabel Text Truncation VS. Line Breaks in Text
Avplayer Shows Black Screen When Playing Multiple Videos in Swift3 iOS
How to Use Nsdateformatter to Venezuela
Issue with Uitableview: Action Only Works Every Second Time
Removing Duplicate Objects from Fetch Based on Object Parameter Updated Swift
Distanceinmeters Problems with Arrays and Sort
Inappropriate Expected Declaration Error
How to Set Action for Uibutton in Uitableviewcell
How to Use Local-Only Project via Cocoapods
How Detect Swipe Gesture Direction