Use this tag only for questions directly pertaining to the Swift Decodable protocol introduced in Swift 4.
Questions tagged [decodable]
678 questions
-1
votes
1 answer
Decodable Dictionary [String : Any]
I'm trying to consume a JSON Rest API via Swifts Decodable class. The API contains a dictionary with keys as Strings and values that sometimes is a String and sometimes is Bool. I've created structs for all subtrees of the JSON, but can't figure out…

Emil Söderlind
- 1
- 2
-1
votes
3 answers
How to parse JSON using swift 4
I am confusing to getting detail of fruit
{
"fruits": [
{
"id": "1",
"image": "https://cdn1.medicalnewstoday.com/content/images/headlines/271/271157/bananas.jpg",
"name": "Banana"
},
{
"id": "2",
"image":…

breath abel
- 31
- 1
- 2
- 9
-1
votes
1 answer
Encodable JSON dictionary in Swift 4
With the help of @matt. I was able to solve it and the finished code is below for anyone who will encounter similer issues in the near future.
Given the below JSON
{
"restaurants": [
{
"id": 1,
"restaurantName":…

Sam Banana
- 57
- 1
- 10
-1
votes
1 answer
structure for Decodable JSON
I am trying to put the following API link into a Decodable JSON in Swift
Link Here
Below is the code to map the link:
import Foundation
struct SelectedCompany: Decodable {
let LastTradePrice: Double
let ListedCompanyID: String
let…

Abdulla
- 51
- 1
- 6
-1
votes
3 answers
Creating a list from Nested JSON using Decodable in Swift 4
I have been able to convert JSON to structs using Swift 4's Decodable, unfortunately i have been unable to do so with a JSON key called "list" , which is a list ([]) that contains other structs.
{
"cod":"200",
"message":0.0061,
"cnt":5,
"list":[ …

Brian Green
- 215
- 3
- 14
-1
votes
1 answer
JSONDecoder Not Parsing Data
I am trying to get data from this URL
https://api.opendota.com/api/heroStats
I have made a struct
struct HeroStats : Decodable {
let localized_name: String
let primary_attr: String
let attack_type: String
let legs: Int
let…

Pegasus
- 85
- 1
- 14
-1
votes
1 answer
Cannot assign value of type '[Currency]?' to type '[Currency]?.Type'
I am trying to decode a struct which has an optional array
struct AppInitData:Decodable{
var ApplicationID:String?
var Currencies = [Currency]?
enum CodingKeys: String, CodingKey {
case ApplicationID = "ApplicationID"
…

RavikanthM
- 468
- 3
- 17
-1
votes
1 answer
Parsing an array using Decodable
Here is my JSON which I am trying to parse and want to understand the container concept.
{
"results": [
{
"type": "TEST",
"date": 1518633000000,
"slots": [
{
"startDatetime": 1518665400000,
"endDatetime": 1518667200000,
…

Xcoder
- 121
- 2
- 11
-1
votes
1 answer
Parse different JSON with Decodable (Nested array)
I'm working on an app from NiceHash api. The JSON I have to work with looks like this:
{
"result":{
"addr":"37ezr3FDDbPXWrCSKNfWzcxXZnc7qHiasj",
"workers":[
[ "worker1", { "a":"45.7" }, 9, 1, "32", 0, 14 ],
…

Beslan Tularov
- 3,111
- 1
- 21
- 34
-2
votes
1 answer
how to use this response in Codable method in iOS swift
{
"response": "success",
"ads": {
"imp_url": "https://github.com",
"ad_type": "Banner Ad",
"ad_tag": "",
"click_url": "https://github.com",
…

Mobile team
- 13
- 1
-2
votes
1 answer
Unable to get JSON response with Decodable in Swift
in postman response structure like this:
{
"categories": [
{
"id": 48,
"name": "Round-The-Clock",
"description": "24 hours round the clock menu",
"status": "enabled",
"products": [
{
…

learn_swift
- 83
- 6
-2
votes
1 answer
How to transfer data between Class/func and View
I decoded json data from an API and now I want to transfer the decoded data to my view where it can be displayed.
the problem is that I cannot transfer the decoded data to my view with @Observable Object.
My decoding class looks like this:
class…

Nicodimarco
- 1
- 1
-2
votes
1 answer
getting deeply nested JSON decoded into Swift
2 Questions
How do I get to the nested "close" value of a specifi item? Do I do this by struct within a struct within a struct to replicate the coding structure.
What do I do with the number "1594647000" do I use enum with CodingKey?
{
…

Bercilak
- 1
- 1
-2
votes
2 answers
what is the right syntax for a json file?
I wish to populate various collection views and table views with data from a json file. However I do not know how to write that JSON file.
here is the data I wish to populate:
2 sectors : "data" and "developers"
each sector contains a number of…

LEKYSMA
- 141
- 10
-2
votes
2 answers
How to parse JSON using Codable in Swift?
I am able to parse JSON using JSONSerialization, but unable to parse with Codable.
the json look like this:
[
{
"id": 1,
"name": "Leanne Graham",
"username": "Bret",
"email": "Sincere@april.biz",
}
Please help me with the…

Swift
- 1,074
- 12
- 46