{"action":"created","issue":{"url":"https://api.github.com/repos/Hearst-DD/ObjectMapper/issues/626","repository_url":"https://api.github.com/repos/Hearst-DD/ObjectMapper","labels_url":"https://api.github.com/repos/Hearst-DD/ObjectMapper/issues/626/labels{/name}","comments_url":"https://api.github.com/repos/Hearst-DD/ObjectMapper/issues/626/comments","events_url":"https://api.github.com/repos/Hearst-DD/ObjectMapper/issues/626/events","html_url":"https://github.com/Hearst-DD/ObjectMapper/issues/626","id":182661946,"number":626,"title":"Mapping dictionary with no name on key?","user":{"login":"Dbigshooter","id":6803648,"avatar_url":"https://avatars.githubusercontent.com/u/6803648?v=3","gravatar_id":"","url":"https://api.github.com/users/Dbigshooter","html_url":"https://github.com/Dbigshooter","followers_url":"https://api.github.com/users/Dbigshooter/followers","following_url":"https://api.github.com/users/Dbigshooter/following{/other_user}","gists_url":"https://api.github.com/users/Dbigshooter/gists{/gist_id}","starred_url":"https://api.github.com/users/Dbigshooter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Dbigshooter/subscriptions","organizations_url":"https://api.github.com/users/Dbigshooter/orgs","repos_url":"https://api.github.com/users/Dbigshooter/repos","events_url":"https://api.github.com/users/Dbigshooter/events{/privacy}","received_events_url":"https://api.github.com/users/Dbigshooter/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":17,"created_at":"2016-10-12T23:49:08Z","updated_at":"2016-10-13T15:34:16Z","closed_at":"2016-10-13T14:20:18Z","body":"Hi there,\r\n\r\nI'm facing a problem, which I can't seem to figure out. I have a JSON dictionary similar to this:\r\n\r\n```\r\n{\"3371\": [{\"id\":11,\"sId\":2,\"dateTime\":\"2016-10-05T04:00:00.000Z\"},\r\n{\"id\":12,\"sId\":3,\"dateTime\":\"2016-10-05T04:00:00.000Z\"}]},\r\n{\"3728\": [{\"id\":3,\"sId\":2,\"dateTime\":\"2016-10-05T04:00:00.000Z\"},\r\n{\"id\":12,\"sId\":3,\"dateTime\":\"2016-10-05T04:00:00.000Z\"}]}\r\n```\r\n\r\nSo a dictionary containing an arrays. The problem seems to be, the key has no name, so I can't figure out how to map it?"},"comment":{"url":"https://api.github.com/repos/Hearst-DD/ObjectMapper/issues/comments/253549836","html_url":"https://github.com/Hearst-DD/ObjectMapper/issues/626#issuecomment-253549836","issue_url":"https://api.github.com/repos/Hearst-DD/ObjectMapper/issues/626","id":253549836,"user":{"login":"devxoul","id":931655,"avatar_url":"https://avatars.githubusercontent.com/u/931655?v=3","gravatar_id":"","url":"https://api.github.com/users/devxoul","html_url":"https://github.com/devxoul","followers_url":"https://api.github.com/users/devxoul/followers","following_url":"https://api.github.com/users/devxoul/following{/other_user}","gists_url":"https://api.github.com/users/devxoul/gists{/gist_id}","starred_url":"https://api.github.com/users/devxoul/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/devxoul/subscriptions","organizations_url":"https://api.github.com/users/devxoul/orgs","repos_url":"https://api.github.com/users/devxoul/repos","events_url":"https://api.github.com/users/devxoul/events{/privacy}","received_events_url":"https://api.github.com/users/devxoul/received_events","type":"User","site_admin":false},"created_at":"2016-10-13T15:34:16Z","updated_at":"2016-10-13T15:34:16Z","body":"```swift\r\nimport UIKit\r\n\r\nlet dict: [String: [String: Any]] = [\r\n  \"1\": [\r\n    \"id\": 1,\r\n    \"sId\": 2,\r\n    \"dateTime\": \"2016-10-05T04:00:00.000Z\",\r\n  ],\r\n]\r\n\r\nclass MyObject: Mappable {\r\n  var id: Int!\r\n  var sId: Int?\r\n  var fieldId: Int?\r\n\r\n  func mapping(map: Map) {\r\n    id <- map[\"id\"]\r\n    sId <- map[\"sId\"]\r\n    fieldId <- map[\"fieldId\"]\r\n  }\r\n}\r\n\r\nfunc myObjects(from json: [String: [[String: Any]]]) -> [Int: [MyObject]] {\r\n  var objects: [Int: MyObject] = [:]\r\n  for (key, array) in dict {\r\n    guard let key = Int(key),\r\n      let objects = Mapper<MyObject>().mapArray(JSONArray: array)\r\n    else { continue }\r\n    objects[key] = objects\r\n  }\r\n  return objects\r\n}\r\n\r\nlet objects = myObjects(from: json)\r\nprint(objects)\r\n```\r\n\r\nThis code will convert your JSON dictionary into:\r\n\r\n```swift\r\n[\r\n  \"2443\": [\r\n    MyObject(id: 354299, sId: 2443)\r\n    MyObject(id: 354300, sId: 2443)\r\n  ],\r\n  \"2448\": [\r\n    MyObject(id: 354312, fieldId: 2448)\r\n  ]\r\n]\r\n```\r\n"}}
{"actor":{"display_login":"devxoul"}}