struct APOD: Codable {
let points: String
let full_name: String
let description: String
}
let decoder = JSONDecoder()
let product = try! decoder.decode(APOD.self, from: jsonData.data(using: .utf8)!)
print(product.full_name)
I have a String called jsonData that comes from: https://www.instagram.com/georgeanisimow/?__a=1. I formatted the file and pasted it into the project just to have something work.
Unfortunately it fails with this error code:
"Thread 1: Fatal error: 'try!' expression unexpectedly raised an error: Swift.DecodingError.keyNotFound(CodingKeys(stringValue: "points", intValue: nil), Swift.DecodingError.Context(codingPath: [], debugDescription: "No value associated with key CodingKeys(stringValue: \"points\", intValue: nil) (\"points\").", underlyingError: nil))"
I am trying to print the value for "full_name" in the JSON.
Here is the begginng of the JSON:
let jsonData ="""
{
"logging_page_id":"profilePage_592027119",
"show_suggested_profiles":false,
"graphql":{
"user":{
"biography":"- Represented by AEFH Talent and CESD Modeling - I travel a lot -",
"blocked_by_viewer":false,
"country_block":false,
"external_url":null,
"external_url_linkshimmed":null,
"edge_followed_by":{
"count":4571
},
"followed_by_viewer":true,
"edge_follow":{
"count":741
},
"follows_viewer":true,
"full_name":"George Anisimow"
}
}
}"""
pointsin the root object of the JSON. The link doesn't show anything.points, full_name, descriptionkeys in theJSONyou have added in the question.