만들기 :아래의 예를 참조하십시오 내 API 요청에 대한 JSON 데이터를 만들기 위해 노력하고있어 JSON의 API 요청
var itemsArray = [String:AnyObject]()
var itemDictionary: [String: Any] = ["employee":"Max Mustermann", "table":"Tisch X"]
for item in items{
let item = item as! Items
itemsArray = ["name": item.name as AnyObject, "quantity": String(item.count) as AnyObject]
}
itemDictionary["items"] = itemsArray
let jsonData = [itemDictionary]
guard let httpBody = try? JSONSerialization.data(withJSONObject: jsonData, options: []) else{
return }
을하고이 내 코드입니다하지만 작동하지 않습니다. 이 코드의 문제점을 모르겠습니다.
누구든지 나를 도울 수 있기를 바랍니다. 그것이 프로젝트를 마치는 마지막 단계입니다.
모습이 https://stackoverflow.com/questions/28325268/convert-array-to-json-string-in-swift –