swift - 难以解码 Swift [Any:Hashable] 字典
问题描述
我对 Swift 很陌生,我正在尝试使用嵌套值解码以下字典
` Data Optional(Dictionary.Keys([AnyHashable("playesOnline")]))
Optional(<__NSSingleObjectArrayI 0x1c421f0b0>(
{
"_id" = {
"$oid" = 5b604f23b48453051501927b;
};
displayName = test;
location = {
city = Philadelphia;
country = US;
latitide = "39.97669982910156";
longditute = "-75.25859832763672";
};
online = 1;
userName = test;
}))`
我有以下结构
import Foundation
struct Player {
let _id: String
let displayName:String
let online: Bool
let latitide: Double
let longitude: Double
let userName : String
enum CodingKeys: String, CodingKey {
case _id
case latitude
case longitude
case location
case online
case userName
}
任何帮助解码上述响应或任何关于如何为嵌套值下标的见解,以便我可以将它们插入到每个条目的 $oid,userName,latitude,longitude 的数组中,我们将不胜感激。
谢谢您的帮助!
解决方案
推荐阅读
- angular - 运行时重新定位角度组件视图
- excel - 带循环和步骤的 VBA 输入框
- d3.js - 使用 d3js 的平行坐标的初始值
- javascript - 上传大文件 (100mb+) 只会使 Chrome 崩溃
- c# - 如何验证文本框不接受电子邮件ID
- android - Microsoft appcenter 并上传 APK,无需在 Ionic 3 应用程序上集成他们的 SDK
- python - 导入pybel后死内核
- java - 在不使用 FileUtils 的情况下在目录 java 中添加新文件之前删除旧文件
- python - 怎么获得
包含与正则表达式匹配的文本
- maven - 如何在关键的 Cloud Foundry 中部署多模块 maven spring boot 项目?