我正在使用下面的JSON POST调用,我正在尝试将JSON数组追加到集合视图搜索栏数组。我已经尽力了,但是我找不到解决方法。
do {
if let json = try JSONSerialization.jsonObject(with: data) as? [[String: Any]] {
for item in json {
let id = item["id"]!
let category = item["category"]!
//print(id,category)
if let people = item["People"] as? [[String:String]] {
for person in people {
//print(person["name"]!, person["age"]!)
self.nameArray.append(person["name"]!)
self.ageArray.append(person["age"]!)
print(self.nameArray)
}
}
}
}
} catch let parseError {
print("parsing error: \(parseError)")
let responseString = String(data: data, encoding: .utf8)
print("raw response: \(responseString!)")
}