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

JSON using Swift 4

First of all, my question may have already been asked but I search on many tutorial and forums and I can't make it works because I'm french and not very good in English. I try to read JSON with my app but It doesn't work. The only thing printed is…
R1'
  • 490
  • 1
  • 5
  • 17
-2
votes
1 answer

How to decode a JSON String in Swift which uses Integer values as Boolean, alternatively can I force SQLite to use true/false instead of 1/0 as Bool

I'm using SQLite with Swift to store some JSON in a table column. I convert a Codable object into a JSON String and store it in the "json" column in my "data" table. id name json 1 item1 {"status" : true} 2 item2 {"status" :…
mrtksn
  • 412
  • 3
  • 18
-2
votes
1 answer

Swift Error wift Json Decoder Fatal error

when try a json file to decode, with the Jsondecoder().decode i get the errwor: Thread 7: Fatal error: 'try!' expression unexpectedly raised an error: Swift.DecodingError.typeMismatch(Swift.Array, Swift.DecodingError.Context(codingPath: [],…
-2
votes
2 answers

get specifc value from json with php

i need to get specific value only from a key, example: i need to get value of the "odd": "6.25" from "name": "Team To Score Last"->"value": "No goal" and the ODD this is my json "response": [ { "league": {}, "fixture": {}, …
Fabio Krueger
  • 65
  • 1
  • 8
-2
votes
2 answers

How to parse a List inside a Json String In java?

Input Json String: "{"predicted_route": [1, 351, 371, 372, 373, 0]}" that has been received after making a Post Request call to a backend server. I would like to extract the List from the JSON String into an ArrayList. I haven't found anything…
-2
votes
1 answer

json.NewDecoder(r.Body).Decode(&admin) returns empty struct

I know there are a lots of people that has run into the same issue but still here I am. I'm pretty sure my code is correct and still the resulting struct is empty. Function : func PostAdminHandler(w http.ResponseWriter, r *http.Request) { …
-2
votes
2 answers

Is there a way to decode JSON into struct without creating top level structure

I need a way to decode JSON into Swift structure, but start decoding not from top level of JSON. For example, I have some JSON response like this {"response": { "name": "John", "id": 2"} } Actually, I need only need the nested object with name and…
cyrmax
  • 1
-2
votes
1 answer

JSON Parsing using multiple cores

iOS devices are getting better, have more cores but how can we get benefit out of it while we are parsing JSON? Currently, I am using JSONDecoder() for JSON Parsing. Is there way we can do it faster? Maybe using multiple threads parsing in parts…
Rajesh Budhiraja
  • 192
  • 1
  • 12
-2
votes
2 answers

getting only one item from decoding json response iOS

I've a response from MapBox API. I want to store each Feature object of features array in a array then want to display from that array to table view. { type: "FeatureCollection", query: [ "u" ], features: [{ id:…
mefahimrahman
  • 197
  • 2
  • 6
  • 29
-2
votes
2 answers

access to this array data

i have this array result with print_r: Array ( [0] => stdClass Object ( [id] => [place_id] => ChIJ7w0gwihoXz4R4F5KVQWLoH0 [label] => Address Downtown - Sheikh Mohammed bin Rashid Boulevard - Dubai -…
daviserraalonso
  • 75
  • 1
  • 13
-2
votes
1 answer

Syntax to access decoded JSON dictionary items in Swift

I am trying to decode some JSON but struggling with how to access the items in the JSON. The JSON looks like this and JSONlint confirms it is valid json { "USD" : {"15m" : 9161.16, "last" : 9161.16, "buy" : 9161.16, "sell" : 9161.16, "symbol" :…
user6631314
  • 1,751
  • 1
  • 13
  • 44
-2
votes
1 answer

Error while trying to phrase JSON with Swift

I'm trying to receive data from a JSON link in Swift Playground on Mac, I've struct all the data, but I'm having issue trying to decode all of the data, receiving the error: "Referencing instance method 'decode(_:from:)' on 'Array' requires that…
-2
votes
2 answers

how to parse nested json with jsondecoder

code = 200; msg = "Verification_OTP"; result = { "customer_email" = "ghg@Gmail.com"; "customer_name" = we; "customer_phone" = 1234567890; otp = 658715; "user_id" = 135; }; I am unable to parse i got nil in response.Here is…
Akshay
  • 425
  • 1
  • 5
  • 16
-2
votes
2 answers

Decode the JSON file in Java

I'm trying to decode JSON file in JSON format using UTF-8, But it's printing no value JSONParser jsonParser = new JSONParser(); FileReader file = new FileReader("C:/Users/aab6cob/Desktop/jsonFile/170902_K0_RUCd_ML_F4974.txt.insights-json"); …
-2
votes
2 answers

Getting an error decoding JSON, Swift 4.2

I am getting an error when decoding JSON in swift 4.2 Expected to decode Array but found a dictionary instead. My JSON Model: public struct NewsSource: Equatable, Decodable { public let id: String? public let name: String? public let…