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

Flutter: How to reach specific JSON body's children

I'm trying to get the body of specific children inside the response body. final response = await http.get(Uri.parse(url)); var json = jsonDecode(response.body); print(json); Output : { "country" : { "name" : "USA" }, "league" : { …
Kucing Malaya
  • 277
  • 3
  • 12
1
vote
1 answer

Convert Response Variable to JSON file

I'm trying to convert the page at https://lpl.qq.com/web201612/data/LOL_MATCH_DETAIL_7325.js to a json file so that I can parse it into a pandas table. I'm using the python requests library and my function looks like this: [1]def…
S.Slusky
  • 232
  • 4
  • 12
1
vote
1 answer

Swift - JSONDecoder & Combine framework issue

I have a search bar inside a view where I can search and the search will be passed to a REST api and the result will be showed on a tableView. Below are my different classes Model: struct MovieResponse: Codable { var totalResults: Int …
aios
  • 405
  • 5
  • 14
1
vote
2 answers

Swift - Initialise model object with init(from decoder:)

Below is my model struct struct MovieResponse: Codable { var totalResults: Int var response: String var error: String var movies: [Movie] enum ConfigKeys: String, CodingKey { case totalResults case…
aios
  • 405
  • 5
  • 14
1
vote
2 answers

String ecoding returns wrong values . 33.48 becomes 33.47999999999999488

I'm trying to create a hash of a give object after converting it to string in swift but the values encoded returned in string are different. print(myObjectValues.v) // 33.48 let mydata = try JSONEncoder().encode(myObjectValues) …
Joe
  • 173
  • 1
  • 15
1
vote
1 answer

Trouble extracting JSON data in Flutter

I'm trying to render a list of elements in Flutter and the list data is coming from a REST API. However, I'm having trouble understanding how to parse this data correctly. I want the parsed data to look like this: ['Chicken roll', 'Fresh salads',…
CodeSadhu
  • 376
  • 2
  • 4
  • 15
1
vote
1 answer

REST-API Returns plain text for status code 200 and json for status code 400

I need to know what is the best practise or best approach when API is returning text (String) for http status code 200 But also it is returning json object for http status code 400 I have networking layer built with native URLSession and using…
1
vote
2 answers

json decode a list return null in flutter

here is the actual api response in postman { "status": 200, "message": "", "data": { "userDetails": { "username": "richu", "email": "test96@gmail.com", "id": "1" }, "posts": [ { "id": "1", "user_id": "1", "post": "post 1 -- hello", "imagepath":…
A.K.J.94
  • 492
  • 6
  • 14
1
vote
2 answers

How do I parse the nested JSON data from Brawl Stars api in Swift?

The API website I used. I made an account -> Documentation -> Brawlers if you want to try it out Here is part of the JSON I want to parse. I want to print the name inside the "starPowers" array as well as the "gadgets" array. { "items":[ { …
1
vote
1 answer

How to fix error "mismatch" in Xcode while trying to decode JSON

I'm new to Swift language and I'm trying to build a simple JSON parsing App in Xcode. Here's an error I get: typeMismatch(Swift.Double, Swift.DecodingError.Context(codingPath: [CodingKeys(stringValue: "Date", intValue: nil)], debugDescription:…
1
vote
1 answer

Swift JSON Decodable \u0000

Problem I'm currently getting JSON from a server that I don't have access to. The JSON I sometimes get will put this character \u0000 at the end of a String. As a result my decoding fails because this character just fails it. I'm trying to debug…
alenm
  • 1,013
  • 3
  • 15
  • 34
1
vote
1 answer

Create Array of Dates from JSON

I would like to create an array of dates (or of tuples including an index and a data) from the following JSON. My code is creating an array but instead of creating an array of dates, it breaks up the dates into characters. What do I need to do to…
user6631314
  • 1,751
  • 1
  • 13
  • 44
1
vote
2 answers

Exclude CodingKeys that doesn't need to be altered?

Say I have a struct User model which has many properties in it. struct User: Codable { let firstName: String let lastName: String // many more properties... } As you can see above it conforms to Codable. Imagine if the lastName property…
Frankenstein
  • 15,732
  • 4
  • 22
  • 47
1
vote
1 answer

How to decode json file produced from curl in php

At the end of my curl, as follows $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { echo "cURL Error #:" . $err; } else { echo $response; } I get this { "status": true, "message":…
Peter
  • 15
  • 6
1
vote
0 answers

jsondecode loading issue in dart

I try to run below code in flutter App but it loads half JSON data, same API when running for a web app it works fine. Any idea how to solve this issue? Example Future test() async{ final response = await http.post( …