使用JSONDecoder Swift解码具有整数值的字符串键

问题描述 投票:-2回答:1

[我正在对来自API的JSON数据进行解码,并且我一直在对图像对象进行解码,该对象的键具有整数值,您可以在所附的屏幕截图中看到它,需要任何帮助。Screenshot

json swift codable jsondecoder
1个回答
0
投票
使用

Codable,您可以使用以下模型来解析以上的JSON响应。

struct Room: Decodable { let roomId: String let name: String let images: [String:String] }
现在,将其解析为,

do { let response = try JSONDecoder().decode([String:Room].self, from: data) print(response) } catch { print(error) }

© www.soinside.com 2019 - 2024. All rights reserved.