'XPC connection interrupted while trying to get data from web api in swift

my json return this

{
"status":"false",
"subjects":
[
{
"id":1,
"subjectName":"English"
},
{
"id":3,
"subjectName":"Mathemetics"
}
]
}

here is the swift code

struct SyllabusSubjects: Codable {
    let subjects: [Subject]
}

struct Subject: Codable {
    let subjectName: String?
}

i am trying to show the list of subjects on a screen when it loads.

func getSubject(pid: String)
    {               
        var url : URL = URL(string: "http://example.com/webapi/Users.php?action=GetParentSubject&pId="+pid)!
        
        let loadsubjectdata = URLSession.shared.dataTask(with: url, completionHandler: dataLoaded) 
        loadsubjectdata.resume()
    }
    
     func dataLoaded(data:Data?, response:URLResponse?, error:Error?){
       
        if let detailData = data{
                    print("detaildata", detailData)
                    let decoder = JSONDecoder()
                    do {
                        let jsondata = try decoder.decode(SyllabusSubjects.self, from: detailData)
                        
                        print(jsondata.subjects)
                        
                    }catch let error{
                        print(error)
                    }
                }else{
                    print(error!)
                }

    }

when i try to print data it shows = 42 bytes along with this error message

keyNotFound(CodingKeys(stringValue: "subjects", intValue: nil), Swift.DecodingError.Context(codingPath: [], debugDescription: "No value associated with key CodingKeys(stringValue: "subjects", intValue: nil) ("subjects").", underlyingError: nil))



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source