Swift 3에서 간단한 JSON 직렬화 원칙을 이해하는 데 시간이 듭니다. 웹 사이트의 JSON을 배열로 디코딩하면 도움이 되었습니까? jsonResult["team1"]["a"]
등으로 액세스 할 수 있습니까? 여기에 관련 코드는 다음과 같습니다Swift를 사용한 JSONSerialization 3
let httprequest = URLSession.shared.dataTask(with: myurl){ (data, response, error) in
self.label.text = "RESULT"
if error != nil {
print(error)
} else {
if let urlContent = data {
do {
let jsonResult = try JSONSerialization.jsonObject(with: urlContent, options:
JSONSerialization.ReadingOptions.mutableContainers)
print(jsonResult) //this part works fine
print(jsonResult["team1"])
} catch {
print("JSON Processing Failed")
}
}
}
}
httprequest.resume()
들어오는 JSON은 다음과 같습니다
{
team1 = {
a = 1;
b = 2;
c = red;
};
team2 = {
a = 1;
b = 2;
c = yellow;
};
team3 = {
a = 1;
b = 2;
c = green;
};
}
감사 스위프트 3에서