Questions tagged [decodable]

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

678 questions
-2
votes
1 answer

Using Coding Keys to exclude values from being decoded

I have the following structure to decode JSON data: UPDATED: struct Section { let owner : String var items : [ValueVariables] } struct ValueVariables : Decodable { var isSelected = false let breed: String let color: String …
John
  • 965
  • 8
  • 16
-2
votes
2 answers

Decoding nested JSON in Swift

I am trying to decode a nested JSON. All values are mapped to nil. Can someone please help me with this. struct CarouselListings: Decodable { var success: Bool var elapsed: Int = 0 let result: Result struct Result: Decodable { let properties:…
Taimur Ajmal
  • 2,778
  • 6
  • 39
  • 57
-2
votes
2 answers

How to parse array using decodable?

How can I parse this kind of array using decodable protocol ? any advice or sample code please ? { "prices": [ [ 1543165872687, 3806.312680456958 ], [ 1543166191453, …
tsniso
  • 621
  • 2
  • 7
  • 16
-2
votes
2 answers

How to parse this type of json format in swift 4 with decodable?

{ "type": "Success", "message": "", "fitting": { "fitterID": "96ba096c-f0aa-11e7-a67a-76478bc72e4d", "fitID": "09d399c0-7d74-4578-a138-5f4b02ba2e80", "leftNotesJSON": "[{\"class\":\"FitNote\",\"text\":\"Saddle…
Ankur Purwar
  • 275
  • 2
  • 9
-2
votes
1 answer

Type Mismatch with Decodable and Object

I've got a problem with parsing data from the server. I've got JSON which has an array of objects, something like this: { "items": [ { "itemType": { "id": 12, "tagId": "FCHA78558D" …
mikro098
  • 2,173
  • 2
  • 32
  • 48
-2
votes
1 answer

JSON Decoding Error with Collection View Cell

I am trying to build an iOS app in Xcode 9.2, Swift 4 that uses a Collection View Cell to display each of the categories in the JSON file. I was working through this tutorial as an example - https://www.youtube.com/watch?v=hPJaQ2Fh7Ao, but I am…
cjochum
  • 79
  • 2
  • 7
-2
votes
1 answer

Initiate Codable Model Class in swift

Is it possible to initiate object which is codable. So that I can add values into variables. Ex: let obj = MyClass() for NSObject class. Something like this. Please help me. Thanks in advance.
-2
votes
2 answers

Swift 4 JSON Decode Root Array

I am having problems in decoding JSON response using Swift 4 Decoding Functionality. I have main construct and it has one inner construct var hr_employees: [Employee]? = []. The problem is JSON not mapping for 'var hr_employees: [Employee]? = []. I…
Vajahat Ali
  • 117
  • 1
  • 7
-2
votes
1 answer

JSON Decodable nested array has varying formats and types

Struggling with figuring out how to treat my decodable array where it has different types and structures. Essentially it is an array of data, which leads to an array of 4 types, and each of these types consists of a further array of search results.…
unicorn_surprise
  • 951
  • 2
  • 21
  • 40
-2
votes
1 answer

Parse json in init, using Decodable protocol

I would like to parse json file in init of my model. I want it to take URL and initialize all stored properties. Like: init(from url: URL) { ... }, so the question is how do I do it? I tried to do it this way: let info = try…
Egor Kolyshkin
  • 117
  • 1
  • 10
-3
votes
1 answer

Swift decode JSON with unknown keys

I have a JSON file in my app bundle that looks like this { "1": "cat", "2": "dog", "3": "elephant" } What I'd like is to be able to find the value for the "2" key for example ("dog"). I'm using this extension to decode the json…
soleil
  • 12,133
  • 33
  • 112
  • 183
-3
votes
1 answer

Decoding properties in Swift/Decodable

A JSON request gives me following structure: "Name": [{ "@LanguageCode": "xx", "$": "Cologne - Cologne\/Bonn Airport" }, { "@LanguageCode": "de", …
PeeWee
  • 11
-3
votes
3 answers

Custom Decoder (or ?) for simple key/value pairs

Say you have a simple struct Stuff // :Codable ??? { a: String b: String c: String } var stuff: Stuff You have messages that look like this msg = "b Peach" in the example stuff.b should be set to "Peach". (That sentence is explicit. So,…
Fattie
  • 27,874
  • 70
  • 431
  • 719
-3
votes
1 answer

Getting JSON Data and parse it into using Decodables. But i am getting some error "The data couldn’t be read because it isn’t in the correct format"

I am getting json response from the server and after that i will decode this json data into my model class. But it shows error "The data couldn’t be read because it isn’t in the correct format". I am using this feature first time in iOS. I actually…
-3
votes
1 answer

Swift decodable json heterogenous array

I have gone through a couple of questions and answers here on SO, and even though they look similar to my question they don't quite address my issue, as I have tried a bunch of them and yet it is not working. Here is my json and the method I have…
codeperfect
  • 84
  • 1
  • 11
1 2 3
45
46