首页 > 解决方案 > 难以解码 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 的数组中,我们将不胜感激。

谢谢您的帮助!

标签: swiftstructenumsnsdictionarycodable

解决方案


推荐阅读