Hello there, i have a json file in my computer. I am trying to read that by this code:
func ReadQuestion(){
let path = "/Users/bishnudas/Documents/ExamFiles/questions.json"
do {
let data = try Data(contentsOf: URL(fileURLWithPath: path), options: .mappedIfSafe)
if(data.count != 0){
let jsonResult = try JSONSerialization.jsonObject(with: data)
self.exampage.ExamQuestion = data
self.exampage.showWindow(nil)
self.window?.close()
}
} catch {
print(error)
}
}
After reading that json file i am sending the data to another window and trying to convert that data like this:
func LoadQuestionPaper(){
do{
let QSJS = try JSONSerialization.jsonObject(with: ExamQuestion!, options:JSONSerialization.ReadingOptions.mutableContainers) as////! NSDictionary
//Getting error signal sigabrt here.
}catch {
print(error)
}
}
Error message in console:
Could not cast value of type '__NSArrayM' (0x7fffa16f0fd0) to 'NSDictionary' (0x7fffa16f32d0).
2019-01-21 13:39:50.214466+0530 Unox Student Console[2071:66993] Could not cast value of type '__NSArrayM' (0x7fffa16f0fd0) to 'NSDictionary' (0x7fffa16f32d0).
Printing description of QSJS:
(NSDictionary) QSJS = <variable not available>
Can anyone help me to solve this, or can suggest me the right way to convert that data into dictionary please?