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

How to parse iTunes API in swift 4?

I need to do an app used to search through the iTunes API. But I can't use any library so it's different than what I'm used to. With this URL I'm supposed to get the first result for "Instagram" search through the software:…
-1
votes
1 answer

Getting Errors when Subclassing JSON (Swift)

I'm fairly new to dealing with JSON data in Swift and I am trying to subclass some products. I don't mean to code dump, but I want to give you the whole picture. I have three errors that say the same thing: Errors thrown from here are not handled…
user11209999
-1
votes
1 answer

Swift store data from a Webrequest into structures

First of all I'm really beginner in Swift. I'm stuck for hours on this. Here is the problem, I'm using AlamoFire in order to make my request func getListFiles(userId: String, page: Int) { let parameters: Parameters = [ "userId":…
Manu13k
  • 326
  • 1
  • 6
  • 20
-1
votes
1 answer

JSON Decoder error when decoding in CollectionView

I am taking an array of urls and decoding them within a Collection View. I have completed this successfully before but am receiving an error this time around. I am receiving the…
JSharpp
  • 459
  • 1
  • 9
  • 21
-1
votes
1 answer

getting error while download response from api

I am downloading json from api with model class but not able to download let me show my code and expected response fro url Response SUCCESS: { "operator_list" = ( { "A_ADDRESS" = "1001, CASABLANCA, SKYLINE OASIS…
Vishal
  • 23
  • 6
-1
votes
1 answer

UICollectionViewCells appear empty while using JSONDecoder

I am trying to use my decoded json data in a UICollectionView. The issue I'm having is that the cells are showing up blank. When I print the for the results of the decoding using print(playing) or print(searchs) the console displays the proper json…
JSharpp
  • 459
  • 1
  • 9
  • 21
-1
votes
1 answer

Android New Version Available - App Update Dialog Using Json From Own Server

I want to show dialogue when new version is available. I want to make a json file into my web server, and I will manually update my app version in json file. and my app will parse this json file and will notify users and showing dialogue box to…
-1
votes
3 answers
-1
votes
2 answers

JSON Decode does not work as expected swift 4

if I want to decode my JSON there is something weird happening. Here's the structs struct chatMessages : Codable { var message: [chatMessage] } struct chatMessage : Codable { var user: String var message: String var status: String …
-1
votes
2 answers

Why #Codable# not working in below code?

I have below code to test Codable protocol and JSONDecoder. import UIKit class ClassA: Codable { var age: Int = 1 } class ClassB: Codable { var ageInfo: ClassA? var name: String } let json4 = """ { "ageInfo": {}, "name":…
ZYiOS
  • 5,204
  • 3
  • 39
  • 45
-1
votes
1 answer

Error in echo JSON object in foreach PHP

Why does not this code output correct? I used this code in many scripts but I receive the following error: Notice: Trying to get property of non-object in C:\Users\TPA-LAPTOP\AppData\Local\Temp\prev3~.php on line 7 Warning: Invalid argument…
-1
votes
2 answers

How do I bake DateFormatter into a Swift struct so that I don't keep needing to tell JSONDecoder?

I am using Swift 4 to decode some JSON from Twitter: struct Tweet: Codable { let id: String let createdAt: Date let text: String enum CodingKeys: String, CodingKey { case id = "id_str" case createdAt = "created_at" …
Dan
  • 5,013
  • 5
  • 33
  • 59
-1
votes
1 answer

Parse More Complex Nested Response

I'm trying parse JSON: { "meta": { "page": 1 }, "search-results": [ { "id": 41528747 } ] } I defined the following structure: public struct PagedCourses: Codable { public struct Meta: Codable { public let…
nik3212
  • 392
  • 1
  • 6
  • 18
-1
votes
1 answer

Getting Error while Using JSONDecodable in swift4?

I'm getting the following error while using JSONDecodable in swift4. "Type UserRegister does not confirm to protocol 'Decodable' " My Model Structure looks like this. struct UserRegister: Decodable { let id : NSInteger let name : String? …
Zac24
  • 2,514
  • 1
  • 23
  • 28
-1
votes
1 answer

Issue With Using JSON Decode for Swift 4 Xcode

I have an issue here... I am using WooCommerce API to get data from database... Everything is great with this code but i have a weird issue with getting Featured photo (featured_src), The featured photo Value is a String when the image of product…