[英]No value associated with key CodingKeys
I'm trying to parse the following json:我正在尝试解析以下json:
"categories": [
{
"id": 42,
"name": "Air Conditioning",
"image_url": "system-data/category/Category-AirConditioning.png",
"image_marker_url": "system-data/category/Marker_Category-Air Conditioning.png",
"status_id": 7,
"created_at": 1580452213,
"updated_at": 1580452213
},
{
"id": 43,
"name": "Car Wash",
"image_url": "system-data/category/Category-Carwash.png",
"image_marker_url": "system-data/category/Marker_Category-Car Wash.png",
"status_id": 7,
"created_at": 1580452213,
"updated_at": 1580452213
},
{
"id": 45,
"name": "Automobile Services",
"image_url": "system-data/category/Category-Automobile.png",
"image_marker_url": "system-data/category/Marker_Category-Automobile Services.png",
"status_id": 7,
"created_at": 1580452213,
"updated_at": 1580452213
},
{
"id": 48,
"name": "Electrical",
"image_url": "system-data/category/Category-Electrical.png",
"image_marker_url": "system-data/category/Marker_Category-Electrical.png",
"status_id": 7,
"created_at": 1580452213,
"updated_at": 1580452213
},
{
"id": 49,
"name": "Generator Repair & Maintenance",
"image_url": "system-data/category/Category-Generator.png",
"image_marker_url": "system-data/category/Marker_Category-Generator Repair & Maintenance.png",
"status_id": 7,
"created_at": 1580452213,
"updated_at": 1580452213
}
]
You need你需要
let categories: [CityCategory]
or或者
struct CityCategoryResponse: Codable{
let cityCat: [CityCategory]
enum CodingKeys: String, CodingKey{
case cityCat = "categories"
}
}
cityCat
isn't a key inside your json , hence the decoder can't find itcityCat
不是 json 中的键,因此解码器找不到它
Had the same issue, but in my case the problem was in a mistyped<\/strong> name of one of my attributes in JSON.有同样的问题,但在我的情况下,问题在于我在 JSON 中的一个属性的名称输入错误<\/strong>。
The attribute name appeared in a number of entities, and I was dumbfounded for a long time as it had been written correctly in the first instance, so I assumed the JSON was correct, until I found the typo in the second instance!属性名出现在多个实体中,一开始就写对了,我傻眼了半天,所以我以为JSON是对的,直到我在第二个实例中发现错字!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.