我正在尝试解析JSON
"post" : {
"name" : “Test”,
"profiePic" : "thumb_small_1526912131.png",
"to_uni" : "0",
"id_user" : "2863",
"post_type" : "0",
"likes" : [
],
"tags" : [
],
"to_name" : “Vivek”,
"comments" : [
]
}
或者可以是以下类型
"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" : [
]
}
因此,为了使用JSONDecoder对此进行解析,我创建了一个结构如下
并按如下方式解码此json
do {
let responses = try JSONDecoder().decode(Response.self, from: (response?.data!)!)
print(responses)
}catch{
print(error)
}
但是我只是因为喜欢值而得到错误,该值是预期对数组进行解码,但却找到了一个字典。,因为该值空白时包含字典时返回字典,所以返回数组,因此如何管理上面的结构中有这种情况?