【发布时间】:2019-11-09 18:34:22
【问题描述】:
如果这个问题被多次回答,我很抱歉,但我正在寻找我自己的特定 json 问题,这就是为什么发布这个,这是我的 json,它是一个通知数组列表,在额外的对象中你可以看到它有合同对象, 现在这个对象正在改变它可以是 json 数组的第二个索引中的活动或反馈我如何制作 Codable 结构来解码这种类型的 json 这是我的结构,我不能在 Codable 中做任何类型
struct Alert: Decodable {
var id: Int?
var isUnread: Bool?
var userId: Int?
var message: String?
var notificationType: String?
var extra: Any?
"value": [
{
"id": 153,
"is_unread": true,
"user_id": 3,
"message": "Contract offered from JohnWick. Click here to see the details.",
"notification_type": "Contract",
"extra": {
"contract": {
"id": 477,
"likes": 0,
"shares": 0,
"account_reach": 0.0,
"followers": 0,
"impressions": 0.0,
"description": "Fsafasd",
"budget": 0.0,
"start_date": null,
"end_date": null,
"status": "pending",
"is_accepted": false,
"brand_id": 443,
"influencer_id": 3,
"proposal_id": 947,
"created_at": "2019-11-09T17:40:57.646Z",
"updated_at": "2019-11-09T17:40:57.646Z",
"contract_fee": 435345.0,
"base_fee": 5000.0,
"transaction_fee": 43534.5,
"total_fee": 483879.5,
"infuencer_completed": false,
"brand_completed": false,
"comments": 0
}
}
},
{
"id": 152,
"is_unread": true,
"user_id": 3,
"message": "Message from JohnWick. Click here to check your inbox.",
"notification_type": "Message",
"extra": {
"message": {
"id": 495,
"body": "Uuhvh",
"read": false,
"conversation_id": 42,
"user_id": 3,
"created_at": "2019-11-08T13:44:02.055Z",
"updated_at": "2019-11-08T13:44:02.055Z"
}
}
},
]
如您所见,它可以是消息、活动、合同或反馈,那么我如何使用 CodingKeys Codable 解析或为此建模
【问题讨论】:
标签: json swift xcode parsing codable