I am currently parsing JSON with Decodable in SWIFT 4.
The JSON is formatted as follows:
{
"autopayout_from": "1.010",
"earning_24_hours": "9.74731104",
"error": false,
"immature_earning": 0.635593030875,
"last_payment_amount": "1.91238210",
"last_payment_date": "Mon, 26 Feb 2018 15:08:02 GMT",
"last_share_date": "Mon, 26 Feb 2018 16:16:01 GMT",
"payout_daily": false,
"payout_request": false,
"total_hashrate": 109006.86,
"total_hashrate_calculated": 143855.75,
"transferring_to_balance": 0.2281390807,
"wallet": "0xbb76fc2ce36a19da28fd713e350a42f1023e2f7f",
"wallet_balance": "0.49556201",
"workers": {
"10003": {
"alive": false,
"hashrate": 0.0,
"hashrate_below_threshold": false,
"hashrate_calculated": 0.0,
"last_submit": "Mon, 26 Feb 2018 13:23:16 GMT",
"second_since_submit": 10612,
"worker": "10003"
},
"100151": {
"alive": false,
"hashrate": 0.0,
"hashrate_below_threshold": false,
"hashrate_calculated": 0.0,
"last_submit": "Mon, 26 Feb 2018 09:30:30 GMT",
"second_since_submit": 24578,
"worker": "100151"
},
"100205": {
"alive": true,
"hashrate": 19.28,
"hashrate_below_threshold": true,
"hashrate_calculated": 24.85,
"last_submit": "Mon, 26 Feb 2018 16:12:02 GMT",
"second_since_submit": 486,
"worker": "100205"
},
I am able to easily parse things such as last_payment_ammount or last_payment_date with my Struct:
struct ticker: Codable{
let error: Bool
let wallet: String
let earning_24_hours: String
let immature_earning: Double
let last_payment_amount: String
let last_payment_date: String
let total_hashrate: Double
let total_hashrate_calculated: Double
let wallet_balance: String
}
What I am really struggling to get my head around is getting the nested stuff.
How can I get for example a list of workers using the "worker" variable for example to maybe put into an array. Or parse the hashrate value for one worker?
Many thanks
Here's how I would model this: