我正在使用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个小时