Questions tagged [jsondecoder]

This tag should be used for `JSONDecoder` (introduced in Swift 4) questions for decoding JSON decoder on Apple platforms.

JSONDecoder is a class, introduced in Swift 4, for decoding JSON on Apple operating systems that conform to Decodable protocol (or Codable protocol, which is type alias for Encodable & Codable). This offers a simple mechanism to easily parse JSON from Decodable Swift types. This applies to standard Swift collections, such as Array and Dictionary, but custom types can conform to Decodable to participate in this simplified JSON decoding process.

This replaces/supplements the JSONSerialiation class used in prior Swift versions.

See also:

528 questions
-1
votes
2 answers

Flutter Post Request with Nested JSON as Data + BLoC pattern

I have tried to pass JSON in Post Request using BLoC Pattern. jsonEncode({ 'MobileNo': _emailController.value, 'Password': _passwordController.value, 'IPAddress': '192.168.0.1', 'Latitude' : '23.04503', 'Longitude':…
Pratik Butani
  • 60,504
  • 58
  • 273
  • 437
-1
votes
1 answer

Convert a json to multi-dimensional PHP array

I have the following json sent to my API endpoint {"key":"levels","value":"[{role_id:1, access_level_id:3}, {role_id:2, access_level_id:1}, {role_id:3, access_level_id:2}]","description":""} at the backend, I receive it as a Laravel request as…
Josh
  • 1,660
  • 5
  • 33
  • 55
-1
votes
1 answer

length of server response in flutter http package

I am using future builder for building list view. I am getting the response from server. I am getting exactly what i need. There is single error that i am trying to resolve. The error is when i fetch data from server using http.get method : String…
M.Adnan Ijaz
  • 91
  • 10
-1
votes
1 answer

How do I parse JSON file with an array of objects in Swift?

For several hours I've been trying to parse to a JSON file with an array to experiment with API's, but I keep getting errors. I managed to parse a file with just one JSON object/dictionary (following different tutorials), but I can't figure it out…
Zemelware
  • 93
  • 8
-1
votes
2 answers

Difficulty parse integer value in JSON using JSON Decoder in Swift

I am trying to decode some JSON from an API that looks like this (foo is short for a list of properties): {"page":1,"total_results":10000,"total_pages":500,"results":[{"foo":"bar"},{"foo":"bar2"},{"foo":"bar3"}]} The struct recommended by…
user6631314
  • 1,751
  • 1
  • 13
  • 44
-1
votes
2 answers

how can i get data from nested arrays through JSONDecoder()

i am facing an issue in my project basically i want to print job listing in which user can see jobs that are available and also show required skills of each job (experience tags) here is my json result { "message": "candidate job…
Usama Hassan
  • 81
  • 1
  • 8
-1
votes
1 answer

Swift decode composite struct data

I have the following json data and trying to parse it, but I get number of objects, but object itself in the array all are nil. I do not want to decode the origin in the following json object. By the way, the following string is first converted to…
casillas
  • 16,351
  • 19
  • 115
  • 215
-1
votes
2 answers

Swift JSONDecode decoding arrays/dictionary fails

This was the struct I was using struct earthquakeResults: Codable{ let datetime: String let depth: String //let eqid: Any let lat: String let lng: String let magnitude: String //let src: Any } This is when I was trying…
-1
votes
1 answer

Swift JSONDecoder type mismatch on parsing ISO8601 DateInterval

I'm trying to parse next sample DateInterval values an Api suplies following ISO 8601 format: [ {"ISO8601":"PT10M","text":"time: 00:10"}, {"ISO8601":"PT1H10M","text":"time: 01:10"}, {"ISO8601":"PT3H20M","text":"time: 03:20"} ] to next…
Matias Masso
  • 1,670
  • 3
  • 18
  • 28
-1
votes
1 answer

How to Parse Json dictonary in swift 4

Hi I have a problem with this Json: { "id": "libMovies", "jsonrpc": "2.0", "result": { "limits": { "end": 75, "start": 0, "total": 1228 }, "movies": [{ "art": { …
TheCesco88
  • 111
  • 4
  • 9
-1
votes
1 answer

JSONDecoder keeps running error, How can I troubleshoot this? It was working last week

I am making an api call and trying to use my JSONDecoder() and it it keeps jumping to my catch. How can I troubleshoot this? Or does anyone else see whats wrong? do{ print("decoding") let decoder = JSONDecoder() …
Andy Nguyen
  • 451
  • 5
  • 17
-1
votes
1 answer

Swift - Expected to decode Array but found a dictionary instead

I have a json like bellow: object{2} status: 1 result{3} cohorts[23] categories[158] languages[16] And I am Decoder it like bellow: struct ResultAPIJSON: Decodable { private enum RootCodingKeys: String, CodingKey { …
jo jo
  • 1,758
  • 3
  • 20
  • 34
-1
votes
1 answer

Make Swift JSONDecoder not fail when type on key not match

I have one simple struct like that: struct Object: Codable { let year: Int? … } It's fine when decode JSON like { "year": 10, … } or no year in JSON. But will fail decode when JSON has different type on key: { "year": "maybe string value"…
user25917
  • 797
  • 7
  • 18
-1
votes
1 answer

Result of call to 'updateWeatherIcon(condition:)' is unused and therefore will not show UIImage

I am building a small Weather app that is accessing the openweathermap API. I am using JSONDecoder to parse the JSON from the API. For the most part, I am able to get most of the data in the simulator. Except for the UIImage that is supposed to…
AltBrian
  • 2,392
  • 9
  • 29
  • 58
-1
votes
3 answers

Swift Codable: Array of Array having Dictionaries

I have a JSON object, I cannot figure out how to access the exclude_list in given JSON. {"variants": {"variant_groups": [ { "group_id":"1", "name":"Crust", …
Rocky
  • 2,903
  • 1
  • 22
  • 26