I am trying to parse JSON which can be
"post" : {
"name" : “Test”,
"profiePic" : "thumb_small_1526912131.png",
"to_uni" : "0",
"id_user" : "2863",
"post_type" : "0",
"likes" : [
],
"tags" : [
],
"to_name" : “Vivek”,
"comments" : [
]
}
or it can be of following type
"post" : {
"name" : “Test2”,
"profiePic" : "thumb_small_1533120835.png",
"to_uni" : "0",
"id_user" : "20393",
"post_type" : "0",
"likes" : {
"message" : “Vivek like this."
},
"tags" : [
],
"to_name" : “Vv”,
"comments" : [
]
}
So for parse this using JSONDecoder I have created a struct as follows
And decoding this json as follows
do {
let responses = try JSONDecoder().decode(Response.self, from: (response?.data!)!)
print(responses)
}catch{
print(error)
}
But i am getting error just for likes value which is Expected to decode Array but found a dictionary instead. because that value when blank it returns dictionary when contain value it returns array, so how to manage this kind of case in above struct?