keyNotFound Error While Trying to Connect to API

I am trying to connect to an API and I am getting the following error:

keyNotFound(CodingKeys(stringValue: “title”, intValue: nil), Swift.DecodingError.Context(codingPath: [CodingKeys(stringValue: “items”, intValue: nil), _JSONKey(stringValue: “Index 0”, intValue: 0)], debugDescription: “No value associated with key CodingKeys(stringValue: "title", intValue: nil) ("title").”, underlyingError: nil))

I have used the following method to parse the JSON data but it keeps throwing the error. I can not figure out what I am doing wrong.

func parse(data: Data) → [SearchResult] {
do {
let decoder = JSONDecoder()
let result = try decoder.decode(ResultArray.self, from: data)
return result.items
} catch {
print(“JSON Error: (error)”)
return []
}
}

Screen Shot 2021-09-16 at 6.04.10 PM

You’ve currently got the meta-data element as part of the activity. The documentation says to make it a child of the application:

In AndroidManifest.xml, add the following element as a child of the <application> element, by inserting it just before the closing </application> tag

So I suggest you try moving it to just after </activity>.

It would help if you posted at least a little of your JSON for us to look at. That said, however, your JSON does not have a title key in the first object in the items array.

Pleased to see your issue as I think I have the same problem, I am also confused and in need of light on this same issue. Need help.

Pleased to see your issue as I think I have the same problem, I am also confused and in need of light on
this same issue. Need help

That’s great. I was impressed by your writing. I am happy to see such a topic. Please come to my blog and read it.

This topic was automatically closed after 166 days. New replies are no longer allowed.