如何在 swift 5 UIImageView 中使用在 mysql 中存储为 blob 的图像?
How to use an image stored as blob in mysql in swift 5 UIImageView?
这就是我的。
import Foundation
struct UserData: Decodable {
let id: Int
let first_name: String
let last_name: String
let gender: String
let email: String
let joined: String
let profile_image: [String:[String]]?
let rating: Float
let rating_count: Int
}
我得到:
typeMismatch(Swift.Array<Any>, Swift.DecodingError.Context(codingPath: [_JSONKey(stringValue: "Index 0", intValue: 0), CodingKeys(stringValue: "profile_image", intValue: nil), _JSONKey(stringValue: "type", intValue: nil)], debugDescription: "Expected to decode Array<Any> but found a string/data instead.", underlyingError: nil))
如果我将结构更改为:
struct UserData: Decodable {
let id: Int
let first_name: String
let last_name: String
let gender: String
let email: String
let joined: String
let profile_image: [String:String]?
let rating: Float
let rating_count: Int
}
我得到:
typeMismatch(Swift.String, Swift.DecodingError.Context(codingPath: [_JSONKey(stringValue: "Index 0", intValue: 0), CodingKeys(stringValue: "profile_image", intValue: nil), _JSONKey(stringValue: "data", intValue: nil)], debugDescription: "Expected to decode String but found an array instead.", underlyingError: nil))
不确定如何获取在数据库中存储为 blob 的图像并将其用作 UIImage。
这是它作为响应返回的方式:
\"profile_image\" = {\n data = (\n 47,\n 57,\n 106,\n 47,\n 52,\n 65,\n 65,\n 81,\n 83,\n 107,\n 90,\n 74,\n 82,\n 103,\n 65,\n 66,\n 65,\n 81,\n 69,\n 65,\n 83,\n 65,\n 66,\n 73,\n 65,\n 65,\n 68,\n 47,\n 50,\n 119,\n 66,\n 68,\n 65,\n 65,\n 89,\n 69,\n 66,\n 81,\n 89,\n 70,\n 66,\n 65,\n 89,\n 71,\n 66,\n 81,\n 89,\n 72,\n 66,\n 119,\n 89,\n 73,\n 67,\n 104,\n 65,\n 75,\n 67,\n 103,\n 107,\n 74,\n 67,\n
..... 它继续前进但因为太长而中断
struct UserData: Decodable {
let id: Int
let first_name: String
let last_name: String
let gender: String
let email: String
let joined: String
let profile_image : Image
let rating: Float
let rating_count: Int
}
struct Image: Codable {
var data: [UInt8]
}
这就是我的。
import Foundation
struct UserData: Decodable {
let id: Int
let first_name: String
let last_name: String
let gender: String
let email: String
let joined: String
let profile_image: [String:[String]]?
let rating: Float
let rating_count: Int
}
我得到:
typeMismatch(Swift.Array<Any>, Swift.DecodingError.Context(codingPath: [_JSONKey(stringValue: "Index 0", intValue: 0), CodingKeys(stringValue: "profile_image", intValue: nil), _JSONKey(stringValue: "type", intValue: nil)], debugDescription: "Expected to decode Array<Any> but found a string/data instead.", underlyingError: nil))
如果我将结构更改为:
struct UserData: Decodable {
let id: Int
let first_name: String
let last_name: String
let gender: String
let email: String
let joined: String
let profile_image: [String:String]?
let rating: Float
let rating_count: Int
}
我得到:
typeMismatch(Swift.String, Swift.DecodingError.Context(codingPath: [_JSONKey(stringValue: "Index 0", intValue: 0), CodingKeys(stringValue: "profile_image", intValue: nil), _JSONKey(stringValue: "data", intValue: nil)], debugDescription: "Expected to decode String but found an array instead.", underlyingError: nil))
不确定如何获取在数据库中存储为 blob 的图像并将其用作 UIImage。
这是它作为响应返回的方式:
\"profile_image\" = {\n data = (\n 47,\n 57,\n 106,\n 47,\n 52,\n 65,\n 65,\n 81,\n 83,\n 107,\n 90,\n 74,\n 82,\n 103,\n 65,\n 66,\n 65,\n 81,\n 69,\n 65,\n 83,\n 65,\n 66,\n 73,\n 65,\n 65,\n 68,\n 47,\n 50,\n 119,\n 66,\n 68,\n 65,\n 65,\n 89,\n 69,\n 66,\n 81,\n 89,\n 70,\n 66,\n 65,\n 89,\n 71,\n 66,\n 81,\n 89,\n 72,\n 66,\n 119,\n 89,\n 73,\n 67,\n 104,\n 65,\n 75,\n 67,\n 103,\n 107,\n 74,\n 67,\n
..... 它继续前进但因为太长而中断
struct UserData: Decodable {
let id: Int
let first_name: String
let last_name: String
let gender: String
let email: String
let joined: String
let profile_image : Image
let rating: Float
let rating_count: Int
}
struct Image: Codable {
var data: [UInt8]
}