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
-2
votes
2 answers

How can I decode this json with Alamofire?

I want to print just value for key "User_number" [ { "User_fullname": null, "User_sheba": null, "User_modifiedAT": "2019-01-31T18:37:02.716Z", "_id": "5c53404e91fc822c80e75d23", "User_number": "9385969339", …
J56
  • 37
  • 5
-2
votes
2 answers

how prepare API response to use with jsonDecoder in swift

when i call API and get response from server with Alamofire, i want use "data" object from json this data come from API { "code": 200, "hasError": false, "data": [ { "userSession":…
Sajjad
  • 1,536
  • 2
  • 17
  • 31
-2
votes
1 answer

Decoding [[String]] using JSONDecoder?

I have been away from Swift for the last 12 months but have just come back to an application that was previously working (Swift 4.0) but now seems to be failing and I am not sure why. My problem relates to the JSONDecoder and trying to decode an…
fuzzygoat
  • 26,573
  • 48
  • 165
  • 294
-2
votes
1 answer

how to parse the key value dictionary data

I have json as below. { "CHF": 1.0064, "KZT": 0.0027, "ZAR": 0.0676, "INR": 0.0136, "CNY": 0.1456, "UZS": 0.0001, "AUD": 0.7062, "KRW": 0.0009 } This is nothing but list of currency & their rates. I am confused how to parse this…
Fahim Parkar
  • 30,974
  • 45
  • 160
  • 276
-2
votes
2 answers

How can I multiply all item in an array with laravel?

i have array in controller with output like this { "usia": 0.01761252446184, "wife_education": 0.078277886497065, "husband_education": 0.0058708414872798, "number_of_children": 0.17025440313112, "wife_religion": 0.86497064579256, …
-2
votes
1 answer

JSONDecoder for custom nested class is not working in swift 4

I am using the following code to decode the data from server to json. But when it is parsing into json. It throws following error The data couldn’t be read because it isn’t in the correct format. struct ExpoDecode: Codable { var success: Bool? var…
Balaji Kondalrayal
  • 1,743
  • 3
  • 19
  • 38
-2
votes
2 answers

Where does JSONDecoder().decode get it's data from?

My apologies if this sounds dumb but where does JSONDecoder get its data from? I keep getting "Grid" and "Red" so I think its just decoding this dummy I set up and not the JSONEncoder().encode(myStarageObject) from the last time the program ran.…
Paul K.
  • 95
  • 1
  • 12
-2
votes
2 answers

Can't return or decode data with JSONDecoder

I am learning to decode data with JSON in an Xcode playground but can't figure out what's wrong with my code, I can't return data nor decode it . Here is my code: import UIKit import…
Wizzardzz
  • 781
  • 1
  • 9
  • 32
-3
votes
1 answer

JSON decoder issue. How I can parse these data?

everyone. I am making an app for iOS. I use an API that allows to fetch city's sights as JSON. Here is an example of the data: { "type":"FeatureCollection", "features":[ { "type":"Feature", "id":"7281004", …
Artemast
  • 7
  • 3
-3
votes
1 answer

convert sql array value result to array php

I have a column of datatype array in sql like: This value is received as : $customlabel = "{new,\"tree test123\",de}" I tried json_decode($customlabel, TRUE) to get it into array. But this just returns empty string
Azima
  • 3,835
  • 15
  • 49
  • 95
-3
votes
2 answers

Invalid conversion from throwing function of type XXXX to non-throwing function type XXXX

I am stuck with this situation where I have a custom JSONDecoder struct which contains a private function to decode data, and another function which is exposed, and should return a specific, Decodable type. I would like these functions to throw…
-3
votes
1 answer

Pass JavaScript array to PHP array

I am New to this. I want to create text file in PHP for that I need two array for Clint side. Problem is that I have passed the array from JavaScript to PHP but In PHP it does convert into single string of array of javascript. test.html
-3
votes
2 answers

How to decode a JSON with 2 structs that has an array

I'm trying to decode a JSON response but I get an error that says: The data couldn’t be read because it isn’t in the correct format The response is in array that went in a ["Product"] node. I get responses but I think the node in…
dreiohc
  • 11
  • 1
  • 5
-3
votes
1 answer

Can't Parse Array JSON Decoder Swift 4

I can't get the JSON data of the link it always get the error. "Expected to decode Array but found a dictionary instead." Thank you. My JSON { server_response: [ { id: "1", magazine_title: "Volume 1 Issue 1", mobile_link: "", magazine_img:…
Guren
  • 182
  • 2
  • 14
-3
votes
3 answers

PHP: JSON_DECODE is not working for the following data

I'm trying to decode this json data by below code, but it's not working. $data = 'VA_OnQueryData({"name":"John","id":"354902332592"});'; return json_decode($data);
Feroz Ahmed
  • 931
  • 10
  • 16
1 2 3
35
36