Python
Java
PHP
IOS
Android
Nodejs
JavaScript
Html5
Windows
Ubuntu
Linux
使用可编码的值,有时是 Int,有时是 String
我有一个 API 有时会返回特定的键值 在本例中id 在 JSON 中作为 Int 有时它会以 String 的形式返回相同的键值 如何使用 codable 来解析该 JSON struct GeneralProduct Codable v
json
swift
swift4
Codable
解码子级时访问嵌套 Codable 结构中父级结构的属性
在嵌套中使用解码器时Codablestruct 有什么方法可以访问父结构的属性吗 我能想到的唯一可行的方法 尚未测试 是在父结构中也使用手动解码器 在userInfo字典 然后访问userInfo在子结构中 但这会产生大量样板代码 我希望有
swift
struct
Decoding
Codable
identifiable
Swift 4 Codable Realm 对象子类
尝试将我的一些代码库切换到 Swift 4 的新版本Codable协议 我的设置看起来像这样 class Base Object Codable dynamic var id String dynamic var timestamp Str
ios
swift
Realm
Codable
在 swift 中使用 UUID() 和 json
我在网上找到了在 json 文件中使用硬编码 uuid 的示例 并且这些示例非常适合我 但是当我在应用程序中添加从 json 数组中删除项目的功能时 我需要动态创建这些 uuid 这是我的json文件 list json 它曾经有硬编码的i
json
swift
Codable
decodable
Swift:可编码 - 提取单个编码密钥
我有以下代码来提取编码密钥中包含的 JSON let value try decoder decode String Applmusic self from 0 applmusic 这成功处理了以下 JSON applmusic code
ios
json
swift
Codable
decodable
Swift 4 JSON Codable - 返回的值有时是一个对象,其他是一个数组
我从 API 获取的数据返回单个对象 但当有多个对象时 它会返回同一键中的数组 对于我正在使用的当前模型 结构 当数组出现时解码会失败 这些结果是随机排序的 这意味着我不知道何时会收到对象或数组 有没有办法创建一个模型 考虑到这一事实 并可
Arrays
json
swift
swift4
Codable
CoreData + Codable 不保存
我正在尝试提取一些数据并将其存储在 CoreData 中 拉取数据工作正常 但数据没有被持久保存 这是我用来尝试保存 CoreData 的代码 guard let codingUserInfoKeyManagedObjectContext
ios
swift
CoreData
Codable
使 Swift 中的类默认符合 Codable
Swift 的这样的特性Codable Decodable Encodable 协议非常有用 但我发现这样的问题 让我们的 Parent 类符合Codable class Parent Codable var name String var
json
swift
inheritance
Codable
Swift Codable:使用未知键解码字典
Codable当您了解 JSON 数据的关键格式时 这会非常有用 但是如果您不知道密钥怎么办 我目前面临这个问题 通常我希望 JSON 数据像这样返回 id lt 123 gt data id
swift
Codable
显式遵守 Codable 删除了结构上的成员初始化程序生成
Given struct Foo let bar Bar 我得到了一个方便的初始化程序来使用 let foo Foo bar Bar But if Bar不是它本身Codable 或者由于某些其他原因我需要明确实现Codable on Fo
swift
Codable
使用可配置键进行 Swift 4 JSON 解码
我是 Swift 新手 我需要用一些东西来解析 JSON可配置按键 与我在这里看到的许多示例相反 密钥是已知的before解码操作开始 它们只依赖于传递给端点的一些参数 Example https some provider com end
json
swift
Codable
可编码:不符合“可解码”协议
无法弄清楚为什么我的课程不符合 Codable 请注意 就我而言 我不需要实现这些方法encode and decode public class LCLAdvantagePlusJackpotCache Codable public le
swift
Codable
decodable
具有多个键和关联值的可编码枚举
我已经看到了有关当所有情况都有关联值时如何使枚举符合 Codable 的答案 但我不清楚如何混合具有和不具有关联值的情况的枚举 如何针对给定情况使用同一密钥的多个变体 如何对没有关联值的情况进行编码 解码 enum EmployeeClas
swift
enums
Codable
Swift Codable:如何将顶级数据编码到嵌套容器中
我的应用程序使用返回 JSON 的服务器 如下所示 result OK data Common to all URLs user name John Smith ETC Different for each URL data for thi
ios
swift
Codable
decodable
encodable
使用 JSONDecoder 解码 PascalCase JSON
我需要用大写首字母 又名 PascalCase 或 UppperCamelCase 解码 JSON 如下所示 Title example Items hello world 所以我创建了一个符合以下条件的模型Codable struct M
json
swift
uppercase
Codable
decodable
如何在可编码结构中使用计算属性(swift)
我创建了一个 可编码 结构来序列化数据集并将其编码为 Json 除了计算属性未显示在 json 字符串中之外 一切都运行良好 如何在编码阶段包含计算属性 Ex struct SolidObject Codable var height Do
ios
json
swift
Codable
computedproperties
如何使用 swift 4 解析 JSON
我对获取水果的细节感到困惑 fruits id 1 image https cdn1 medicalnewstoday com content images headlines 271 271157 bananas jpg name Ban
json
swift
Codable
decodable
使用 swift Codable 从 JSON 数组中提取数据
我有一个像这样的 JSON 响应 我目前设计的可解码结构如下 struct PortfolioResponseModel Decodable var dataset Dataset struct Dataset Decodable var
json
swift
swift4
Codable
decodable
使用 Swift 将可编码结构保存到 UserDefaults
我正在尝试对结构进行编码 struct Configuration Encodable Decodable private enum CodingKeys String CodingKey case title title case con
swift
Codable
userdefaults
Swift 可编码,当 JSON 中缺少键时,类属性的默认值
如您所知 Codable 是 swift 4 中的新东西 因此我们将从旧的模型初始化过程转向这一过程 通常我们使用以下场景 class LoginModal let cashierType NSNumber let status NSNum
ios
swift
xcode
swift4
Codable
1
2
3
4
»