如何将 NSInlineData 转换为字符串?
How to convert NSInlineData to string?
在我的应用程序中,我实现了 google 地图街景,所以我使用 AFNetworking 解析街景 api,但响应对象是 NSInline 数据,无法转换为字符串,请帮助我获取对象..
编码部分是,
let manager = AFHTTPSessionManager()
manager.requestSerializer = AFJSONRequestSerializer()
manager.responseSerializer = AFHTTPResponseSerializer()
manager.responseSerializer.acceptableContentTypes = NSSet(array: ["text/plain", "text/html", "application/json", "image/jpeg"]) as Set<NSObject> as Set<NSObject>! as! Set<String>?
let url:NSString = NSString(format: "https://maps.googleapis.com/maps/api/streetview?size=400x300&location=29.812113,-95.441671&heading=151.78&pitch=-0.76&key=AIzaSyBzUYqzUts1fwZMG3EPGZyi3_aMr632HGJBH" as NSString)
print(url)
manager.get(url as String, parameters: nil, progress: nil, success: {
(operation, responseObject) in
let locStr:String = responseObject as! String . -->here error shows like could not cast value type nsinlinedata to string.
print("locStr is:",locStr)
}, failure: {
(operation, error) in
print(error)
})
你的响应对象是数据类型,试试:
if let data = responseObject as? Data {
let dataStr = String(data: data, encoding: .utf8)
}
在我的应用程序中,我实现了 google 地图街景,所以我使用 AFNetworking 解析街景 api,但响应对象是 NSInline 数据,无法转换为字符串,请帮助我获取对象..
编码部分是,
let manager = AFHTTPSessionManager()
manager.requestSerializer = AFJSONRequestSerializer()
manager.responseSerializer = AFHTTPResponseSerializer()
manager.responseSerializer.acceptableContentTypes = NSSet(array: ["text/plain", "text/html", "application/json", "image/jpeg"]) as Set<NSObject> as Set<NSObject>! as! Set<String>?
let url:NSString = NSString(format: "https://maps.googleapis.com/maps/api/streetview?size=400x300&location=29.812113,-95.441671&heading=151.78&pitch=-0.76&key=AIzaSyBzUYqzUts1fwZMG3EPGZyi3_aMr632HGJBH" as NSString)
print(url)
manager.get(url as String, parameters: nil, progress: nil, success: {
(operation, responseObject) in
let locStr:String = responseObject as! String . -->here error shows like could not cast value type nsinlinedata to string.
print("locStr is:",locStr)
}, failure: {
(operation, error) in
print(error)
})
你的响应对象是数据类型,试试:
if let data = responseObject as? Data {
let dataStr = String(data: data, encoding: .utf8)
}