launchdata.json:
[
{
"name": "Smartcard",
"imageName": "Smartcard",
"description": "A all new way to buy and sell stuff featuring RFID and NFC for touchless transactions and with local server you can pay with your phone.",
"department": "Ticki Finance",
"productid": 1737484,
"id": 1,
"creator": "The Ticki Team"
},
{
"name": "Ink pad",
"imageName": "Inkpad",
"description": "A quick and easy way to take fingerprints and stamp stamps:), And with a quick water activation taking only 15 seconds you can setup in no time. Also, refilling the ink chamber is super easy, all you have to do is put ink in the middle hole.",
"department": "Ticki Design",
"productid": 7338388,
"id": 2,
"creator": "The Ticki Team"
},
{
"name": "Wallet",
"imageName": "Wallet",
"description": "Ever had issues with your credit cards falling out of your pocket/wallet? Well this fixes any issues. Introducing Ticki Wallet. ",
"department": "Ticki Finance",
"productid": 2444495,
"id": 3,
"creator": "The Ticki Team"
},
{
"name": "Pencil Case",
"imageName": "PencilCase",
"description": "I always lose my my pencils. How about you? Well i'm fixing that today with ticki pencil case. A pencil case that can hold pencils, an eraser, and of course, tickies.",
"department": "Ticki Design",
"productid": 3840398,
"id": 4,
"creator": "The Ticki Team"
}
]
Load function:
func load<T: Decodable>(_ filename: String) -> T {
guard let fileUrl = Bundle.main.url(forResource: filename, withExtension: nil) else {
fatalError("Couldn't find \(filename) in main bundle.")
}
do {
let data = try Data(contentsOf: fileUrl)
let decoder = JSONDecoder()
let decodedObject = try decoder.decode(T.self, from: data)
return decodedObject
} catch {
fatalError("Couldn't parse \(filename) as \(T.self):\n\(error)")
}
}
Error:
Thread 1: Fatal error: Couldn't parse Launchdata.json as Array<Product>:
dataCorrupted(Swift.DecodingError.Context(codingPath: [], debugDescription: "The given data was not valid JSON.", underlyingError: Optional(Error Domain=NSCocoaErrorDomain Code=3840 "Invalid value around line 1, column 0." UserInfo={NSDebugDescription=Invalid value around line 1, column 0., NSJSONSerializationErrorIndex=0})))
Post
Replies
Boosts
Views
Activity
I keep getting Thread 1: Fatal error: Couldn't parse Launchdata.json as Array<Product>: When loading this file:
[
{
"name":"Smartcard"
"imageName":"Smartcard"
"description":"A all new way to buy and sell stuff featuring RFID and NFC for touchless transactions and with local server you can pay with your phone."
"department":"Ticki Finance"
"productid":"1737484"
"id":1
"creator":"The Ticki Team"
},
{
"name":"Ink pad"
"imageName":"Inkpad"
"description":"A quick and easy way to take fingerprints and stamp stamps 😝, And with a quick water activation taking only 15 seconds you can setup in no time. Also, refilling the ink chamber is super easy, all you have to do is put ink in the middle hole."
"department":"Ticki Design"
"productid":"7338388"
"id":2
"creator":"The Ticki Team"
},
{
"name":"Wallet"
"imageName":"Wallet"
"description":"Ever had issues with your credit cards falling out of your pocket/wallet? Well this fixes any issues with the. Introducing Ticki Wallet. "
"department":"Ticki Finance"
"productid":"2444495"
"id":3
"creator":"The Ticki Team"
},
{
"name":"Pencil Case"
"imageName":"PencilCase"
"description":"I always lose my my pencils. How about you? Well i'm fixing that today with ticki pencil case. A pencil case that can hold pencils, an eraser, and of course, tickies."
"department":"Ticki Design"
"productid":"3840398"
"id":4
"creator":"The Ticki Team"
with this code:
func load<T: Decodable>(_ filename: String) -> T {
let data: Data
guard let file = Bundle.main.url(forResource: filename, withExtension: nil)
else {
fatalError("Couldn't find \(filename) in main bundle.")
}
do {
data = try Data(contentsOf: file)
} catch {
fatalError("Couldn't load \(filename) from main bundle:\n\(error)")
}
do {
let decoder = JSONDecoder()
return try decoder.decode(T.self, from: data)
} catch {
fatalError("Couldn't parse \(filename) as \(T.self):\n\(error)")
}
}
Please help!!!!
-techboss_11123
When i try to run this code i get "Type 'Account_Admin' does not conform to protocol 'Decodable'" "Type 'Account_Admin' does not conform to protocol 'Encodable'" "Type 'Account_Admin' does not conform to protocol 'Decodable'"
Swift code:
import SwiftUI
public var islogged: Bool = false
struct Account_Admin: Hashable, Codable, Identifiable{
var id: Int
var name: String
var nickname: String
var age: Int
var purchases: Int
var isinguestac: Bool
var tickies: Int
var profilepic: Image
var role: Role
enum Role: String, CaseIterable, Codable{
case Admin = "Admin"
case Developer = "Developer"
case Manager = "Manager"
case Designer = "Designer"
}
private var imagename: String
var image: Image{
Image(imagename)
}
}