我正在使用 JSON 解码器来解码一些 Instagram 用户。这是模型:
struct User: Decodable {
var clear_client_cache: Int
var has_more: Int
var hashtags: String?
var places: String?
var rank_token: String?
var status: String?
var users: [Users]?
struct Users: Decodable {
var position: Int
var user: InstaUser?
struct InstaUser: Decodable {
var byline: String?
var follower_count: Int?
var full_name: String?
var has_anonymous_profile_picture: Int?
var is_verified: Int?
var mutual_followers_count: Int?
var pk: Int?
var profile_pic_id: String?
var profile_pic_url: String?
var unseen_count: Int?
var usernam: String?
}
}
}
{
"clear_client_cache" = 0;
"has_more" = 0;
hashtags = (
);
places = (
);
"rank_token" = "3b22a104-7ac5-4052-be10-e7a7be4e67b4";
status = ok;
users = (
);
}
typeMismatch(Swift.Int, Swift.DecodingError.Context(codingPath: [CodingKeys(stringValue: "clear_client_cache", intValue: nil)], debugDescription: "预期解码 Int 但找到了一个数字。", underlyingError: nil))
比我刚用
let user = try? decoder.decode(User.self, from: response.data!)
它说它想要一个数字,怎么了?对不起,也许它太简单了,但我已经编码了 12 个小时