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
0 answers

Getting "JSONDecodeError: Expecting value: line 1 column 1 (char 0)" on Python while trying to read downloaded twitter txt data

Getting "JSONDecodeError: Expecting value: line 1 column 1 (char 0)" error when I try to read the Twitter streaming data I downloaded using Stream and saving in txt format. Have tried various changes to the codes as suggesting in similar questions…
0
votes
0 answers

JSONDecoder save JSON data into CoreData without loop

I started my iOS Journey just 2 weeks ago & I am faced with a Brick wall at the moment, I need save API responses directly into CoreData, Currently I have to loop my Object after Decoded so I can bring out the values individually & save them. Is…
truthsayer
  • 397
  • 2
  • 8
  • 22
0
votes
2 answers

Decoding Data Using 'Codable'

I am trying to decode an array of my model objects(Catalog) from a JSON that looks like this after serialization of corresponding 'Data' object. { "id" : 5, "catalogs" : [ {catalogKeyValue1},{catalogKeyValue2}] } My model object looks like…
0
votes
1 answer

Cannot invoke 'decode' with an argument list of type '(Codable.Type?

I'm refactoring (trying to) some network code made by an ex-colleague and I wanted to use the new JSONDecoder. His network code is wrapped into a function getData: func getData(modelToReturn:Proto.Type, configuredRequest:URLRequest) { As you can…
user5273262
0
votes
1 answer

Cannot invoke 'decode' with an argument list of type '(Decodable, from: Data)'

I have the following example code in a Playground. I want to decode the result of a network request if that result conforms to the Decodable protocol. Any idea why this code does not work? protocol APIRequest { associatedtype Result } func…
Balázs Vincze
  • 3,550
  • 5
  • 29
  • 60
0
votes
1 answer

Initialising model object without optionals

The model object is populated using JSONDecoder method. Since it is needed to pass it on tableview i need to initialise a local variable of type KBArticle on UI side. Is there any possible method of initialising an object of the KBArticle without…
Vaisakh KP
  • 467
  • 1
  • 6
  • 25
0
votes
3 answers

Decoding JSON to Swift Model Not Root Level

I have the following model: struct Article: Decodable { let title: String let description: String let imageURL: String private enum CodingKeys: String, CodingKey { case title case description case imageURL…
john doe
  • 9,220
  • 23
  • 91
  • 167
0
votes
3 answers

Sending string from JSON data to variable outside of the function

I am attempting to take a string from JSON data and set it to a variable. My problem is that the variable shows as empty. I am using JSONDecoder to retrieve the JSON data and setting the string to a variable outside of the function. I then want to…
JSharpp
  • 459
  • 1
  • 9
  • 21
0
votes
1 answer

Expected to decode Dictionary but found an array instead.", underlyingError: nil))

I trying to parse some json using swift 4 and using decode. What I am confused is on the Expected to decode Dictionary but found an array instead.", underlyingError: nil)) I am new to using decode and new to swift in general so I was…
Zubair Amjad
  • 621
  • 1
  • 10
  • 29
0
votes
0 answers

Python3 json load issue

I am trying to parse empty json file and trying to append the new data inside the Array. this is what I am trying for: [{'key1': 'value1'}, {'key2': 'value2'}] here is my code: import json import argparse import sys def main(): parser =…
devops_coder
  • 51
  • 1
  • 4
0
votes
1 answer

Sort through JSON to find each instance that a string is different

I am attempting to find each instance of the string name: being different. As for the example of JSON below I want to pull Alamo Draft House Lamar and Alamo Draft House Ritz and place them into an array. JSON: [{ "tmsId": "MV011110340000", "rootId":…
JSharpp
  • 459
  • 1
  • 9
  • 21
0
votes
2 answers

How do i parse the json array in tableview in swift 4 using decoder

I am very new to Swift 4 and I am not able to get an example on parsing JsonArray using JSONDecoder. Below is the JSON Response which I am trying to parse from past many days. { "News": [ // how can i use this news as key in swift and parse it …
Gary
  • 5
  • 2
0
votes
1 answer

How can i make an http get request with dictionary as parameter in swift

Here is the API Call how can I pass a dictionary as the parameter to the URL which is a get request, Don't want to use Alamofire in this. The URL is -…
0
votes
0 answers

Dynamically Cast a String to JSONDecoder Decodable.Protocol Type

I have some enum values that I would like to cast to a JSONDecoder Decodable.Protocol type that can be used in the decode method. Each of the Attributes enums Correspond to a Codable class. enum Attributes : String { case Shapes = "GetShapes" …
user-44651
  • 3,924
  • 6
  • 41
  • 87
0
votes
3 answers

Form post has "%10" written by user - json_decode() fails with urldecode()

Was so awesome of the customer to type "%10" instead of "10%" 0_o $PACKAGE_json_decode = json_decode(urldecode(($_POST['textarea']), true); print_r($PACKAGE_json_decode); // LENGTH 0 foreach($PACKAGE_json_decode as $row){ } ERROR: "Message:…
user8588978