【发布时间】:2020-12-04 04:22:40
【问题描述】:
我正在使用 Alamofire 和 Codable 处理这个 JSON:
[
{
"pID": "37229890-dcd8-36c4-bb63-e7b174aafeb7",
"type": "FIRST",
"content": {
"id": "ff64",
"ret": {
"name": "A",
"logoUrl": "hpng"
},
"amo": {
"value": 120.00,
"currency": "EUR"
},
"s": {
"value": 1.20,
"currency": "EUR"
},
"datetime": "",
"p": [
{
"ti": "",
"pr": {
"value": 120.00,
"currency": "EUR"
},
"pic": "string"
}
]
}
},
{
"pID": "37229890-dcd8-36c4-bb63-e7b174aafeb7",
"type": "RATE",
"content": "Rate this app"
}
]
如您所见,“内容”类型的值可以是简单的字符串或结构。
我尝试了一个自定义解码器并拥有一个顶级结构,但我无法解决这个问题。
解决这个问题的最佳方法是什么?
【问题讨论】:
-
是的。向我们展示您尝试了什么以及您的 Codable 看起来如何 + 您如何尝试解码 json。
标签: ios json swift alamofire codable