Questions tagged [codable]

Use this tag only for questions directly pertaining to the Swift Codable protocol introduced in Swift 4.

Serialization / deserialization protocol composed of Encodable and Decodable protocols. Introduced in Swift 4.

References

1568 questions
-1
votes
1 answer

Swift JSON Codable Type Missmatch Vice Versa

I have a problem with parsing JSON in a Codable Struct. I will post 2 different Trys with each the opposite Behaviour. Try 1: var url = URL(string: "https://api.imgflip.com/get_memes") let task = URLSession.shared.dataTask(with: url!) { (data,…
Midoxx
  • 67
  • 7
-1
votes
1 answer

Decode a JSON array

I'm just learning the Swift Decodable protocol and am running into a problem. I am able to decode one json object into a swift object, but am stuck with decoding an array. What goes well: imagine following json: let json = """ { "all" : { …
Bjorn Morrhaye
  • 687
  • 9
  • 30
-1
votes
2 answers

Use Codeable for dictionary

I am trying to use Codeable for the following response from the API { "id": "1", "name": "Demo 1", "description": "Description 1", "created": "2020-04-12T17:20:32.687628Z", "creator": { "id": 10, "name": "My…
Bob
  • 8,392
  • 12
  • 55
  • 96
-1
votes
1 answer

swift json help in displaying data on table view controller

// my url // https://fetch-hiring.s3.amazonaws.com/hiring.json /* my json [ {"id": 383, "listId": 4, "name": ""}, {"id": 472, "listId": 1, "name": ""}, {"id": 625, "listId": 2, "name": null} ] */ // my main vc…
Akbar
  • 15
  • 10
-1
votes
1 answer

Swift.DecodingError.typeMismatch(Swift.Dictionary, Swift.DecodingError.Context(codingPath:)

I'm trying to decode the string values for alias in categories into an enum. And I'm getting the below error. What am I doing wrong? Swift.DecodingError.typeMismatch(Swift.Dictionary, Swift.DecodingError.Context(codingPath:…
jayn
  • 11
  • 6
-1
votes
1 answer

How to resolve error in unit testing when we have Date comparison in Codable

I tried to use custom date strategy in json decoding using Codable as describe in https://stackoverflow.com/a/28016692/3477974 . Here is the simplified implementation code: public extension Formatter { static let iso8601: DateFormatter = { …
Soheil Novinfard
  • 1,358
  • 1
  • 16
  • 43
-1
votes
1 answer

Why I can't parse the following json?

I have json response that I need to parse that, according to the https://newsapi.org web site, should look like: { "status": "ok", "totalResults": 4498, "articles": [{ "source": { "id": null, "name":…
Valter
  • 41
  • 10
-1
votes
2 answers

Convert Codable object to Dictionary without Bool turning to NSNumber

I have a Codable object that I need to convert to Dictionary so I first encode it to convert it to Data and then use JSONSerialization to convert that Data to Any and then use as? [String: Any] to get the dictionary. The conversion is successful…
user121095
  • 697
  • 2
  • 6
  • 18
-1
votes
1 answer

Save to CoreData array of strings with Codable

I'm stuck. I have json (array of Movies). I'm trying parse it with Codable protocol, and save to Core Data. Problem is that Movie object have array of Genres (array of strings). I created two entities: Movie and Genre (with relation One to Many).…
Sergey Krasiuk
  • 198
  • 2
  • 9
-1
votes
1 answer

Decoding JSON with Codable works for one call but not another with the same properties

I am working on a project involving Earthquakes, I have made a call to this URL of Earthquakes with a magnitude of 4.5 and greater and the Data gets decoded correctly. I see the response on the console:…
abcdefg
  • 97
  • 1
  • 9
-1
votes
1 answer

How to create a model class and access the values from JSON response using Codable in ios swift?

I'm learning how to create a model class and using Codable protocol how to access the values for JSON response. Using Alamofire get a request for API call. Here my code my model class class UserDic:Codable{ var batters:Batter? var id:Int? …
saravanar
  • 639
  • 2
  • 11
  • 25
-1
votes
2 answers

swift JSONDecoder parse single Object into Object-Array

I have a Json-file with multiple "Dozzs" objects. Inside each "Dozzs" object is one or multiple "Dozz" objects. So I have a mix of "Dozzs" objects with one "Dozz" and "Dozzs" objects with an array of "Dozz" objects. But I can't say in my struct let…
-1
votes
1 answer

How I parse Following response using Codable?

How to parse the following response using Codable { "Response": { "ResponseStatus": 1,`enter code here` "TraceId": "00125bf6-a416-4095-893c-05e05f8c7202", "Origin": "BOM", "Destination": "PNQ", "Results":…
-1
votes
1 answer

How do I get this certain data set from json api in Swift?

I am currently using Tracker Networks Apex Legends API version 2. I am trying to get the Legend’s data for each legend and then be able to show the data for each specific legend. However, I cannot figure out an easy way of doing this. Any ideas on…
Ron
  • 161
  • 1
  • 8
-1
votes
1 answer

Missing part from the JSON

I have hit a wall that I cant find the way around. I have a JSON file that I am trying to decode but there is a part of the JSON that is missing. I always get nil even though I know that there is supposed to be data there. This is the first part of…