intsig171 / SmartCodable

SmartCodable is a data parsing library based on Codable. It is simple to use, with robust compatibility being one of its main features. SmartCodable 是基于Codable实现的数据解析库。简单易用,强悍的兼容性是SmartCodable的主要特点。 表层API和功能几乎和HandyJSON一致,支持快速的迁移。
https://smart-codable.vercel.app
MIT License
417 stars 43 forks source link

map映射是如何使用的? #43

Closed ET-LINK closed 2 months ago

ET-LINK commented 3 months ago

刚更新到4.1.1

public struct EGNetworkRecordWorkflowTaskRequest: SmartCodable {
    public init() {}
    public var workflowAgentId: String = "assistants.voice_summary.bot.lite"
    public var params: EGNetworkRecordWorkflowTaskParameters?

    public static func mappingForKey() -> [SmartKeyTransformer]? {
        return [
            CodingKeys.workflowAgentId <--- "workflow_agent_id"
        ]
    }
}

public struct EGNetworkRecordWorkflowTaskParameters: SmartCodable {
    public init() {}
    public var filePath: String?
    public var language: EGRecordLangague?

    public static func mappingForKey() -> [SmartKeyTransformer]? {
        return [
            CodingKeys.filePath <--- "file_path"
        ]
    }
}

toJSONString()结果是{\"params\":{\"filePath\":\"files\\/uploads\\/2024-08-08\\/1723104522新录音 8.m4a\",\"language\":\"en-US\"},\"workflowAgentId\":\"assistants.voice_summary.bot.lite\"}, workflowAgentIdfilePath没有映射键

intsig171 commented 2 months ago

这是一个新功能。 请升级到新版本。 使用let string = model.toJSONString(useMappedKeys: true)