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
0
votes
1 answer

How to parse below dynamic JSON in swift 4.2?

{ "payload": { “key1”: “value1”, “key2”: "{\"command\": \"playSound\",\"tone\": 0,\"delay\": 100000}”, “key3”: 0 }, } Above is my response data, whereas 'payload' is known key but inside 'payload' all keys & values are unknown.…
Sunil Targe
  • 7,251
  • 5
  • 49
  • 80
0
votes
3 answers

How to convert an array of images to a string

I am able to fetch json from an api. I have populated all the other views except the imageView. I have an array of images which are string urls. I want to download these images. I'm currently using SDWebImage. I need to convert this array into a…
sk123
  • 580
  • 1
  • 8
  • 29
0
votes
1 answer

Swift Decoder Cannot invoke 'decode' with an argument list of type '(VrOpsObjectStatistics!, from: Data)'

Hi Guys, I am decoding data which is coming from backend system to JSON with: JSONDecoder().decode(<#T##type: Decodable.Protocol##Decodable.Protocol#>, from: <#T##Data#>). I did it often for different kinds of data types, but this time I got the…
Ertan Metin
  • 1
  • 1
  • 2
0
votes
1 answer

How to parse a json dictionary in swift 4 , each containing different keys with decodable protocol?

I have to parse this json Dictionary having different keys. In this example only object_summary key is same while the other keys are different in all the objects. I want to parse this using Swift 4 Decodable protocol with JSONDecoder().…
Neo123
  • 29
  • 4
0
votes
3 answers

Generic networking decoding with Codable & JSONParser

i have 2 main parts in my app infrastructure. NetworkingManager NetworkRequest My goal is to have the request hold its Codable Type so when networking is done the Manager layer can instantiate new instance with the correct type by using…
orthehelper
  • 4,009
  • 10
  • 40
  • 67
0
votes
0 answers

Swift Codable - Parse JSON which contain array or dictionary type not confirm

I am trying to parse JSON which can be "post" : { "name" : “Test”, "profiePic" : "thumb_small_1526912131.png", "to_uni" : "0", "id_user" : "2863", "post_type" : "0", "likes" : [ ], "tags" : [ ], "to_name" :…
Vivek Goswami
  • 432
  • 3
  • 16
0
votes
1 answer

Swift 4 JSON decoding

I am trying to decode JSON. My swift function for decoding the JSON is: func GetChapInfo(){ let endpoint = "https://chapel-logs.herokuapp.com/chapel" let endpointUrl = URL(string: endpoint) do { var request = URLRequest(url:…
Seth Wheeler
  • 353
  • 1
  • 2
  • 16
0
votes
2 answers

Swift 4 - String Conversion to Capital Case During Decoding

In decoding JSON with Swift 4, I would like to convert a string during decoding into capital case. The JSON stores it as uppercase For example let title = "I CANT STAND THE RAIN" print(title.capitalized) How can I do this during the decoding…
Ray Saudlach
  • 530
  • 1
  • 6
  • 19
0
votes
3 answers

JSONDecoder - "Expected to decode Dictionary but found a string/data instead."

So i am trying to decode a json and get this error. This is the JSON : { "SERVERWebSystemInfoGet": { "Return Code" : 0, "Return String" : "No Error", "Info" :…
ironRoei
  • 2,049
  • 24
  • 45
0
votes
1 answer

Alamofire + Decodable - how turn responseJSON to NSData

I'm pretty sure that my problem is easy solving, but I can't find any solution. So I have Alamofire request and have a trouble with handling data types. I have so many 'printing out' just to check what data I've got step by…
nastassia
  • 807
  • 1
  • 12
  • 31
0
votes
2 answers

file_get_contents json decode showing nothing

I m using google site verification recaptcha API for my website. $json = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$secret."&response=".$response."&remoteip=".$ip); when I print echo $json; its showing proper…
Jordan
  • 39
  • 1
  • 13
0
votes
2 answers

Use Swift Decoder to pull attributes from JSON array

I have a JSON array created using this call: guard let json = (try? JSONSerialization.jsonObject(with: content, options: JSONSerialization.ReadingOptions.mutableContainers)) as? [Any] else { print("This is not JSON!!!") return } I am trying…
Jacobi
  • 21
  • 1
  • 6
0
votes
1 answer

Swift - passing types dynamically to JSONDecoder

I am trying to decode from json objects with generic nested object, and for this I want to pass the type of class dynamically when decoding. For example, my classes are EContactModel and ENotificationModel which extend ObjectModel (and :Codable)s.…
Andrei F
  • 4,205
  • 9
  • 35
  • 66
0
votes
1 answer

Swift - JSONDecoder - decoding generic nested classes

I am very new to Swift and I am trying to create a tree of classes to model my data. I want to use JSONEncoder and JSONDecoder to send and receive objects. I have an issue when decoding generic classes inside another object (nested) because in the…
Andrei F
  • 4,205
  • 9
  • 35
  • 66
0
votes
1 answer

JSON Parsing only specific keys in swift

I'm working on iOS App in Swift programming language I've data in below JSON format: [{ "agid": 10, "alarmStatus": 8, "alarmTransactions": [{ "alarmTransactionID": 1, "systemID": 1, "agid": 10, "assignedTo":…
Satyam
  • 15,493
  • 31
  • 131
  • 244