從JSON數據我有一些JSON如下檢索基於ID
[
{
"id": "1",
"locid": "352260",
"name": "Clifton-on-Teme",
"postcode": "WR6 6EW",
"club": "Warley Wasps",
"lat": "52.257011",
"lon": "-2.443215",
"type": "Soil"
},
{
"id": "2",
"locid": "310141",
"name": "Drayton Manor",
"postcode": "ST18 9AB",
"club": "Warley Wasps",
"lat": "52.745810",
"lon": "-2.102677",
"type": "Soil"
},
(這是的套2的提取物。)
和我有一個碼查找如下
func downloadtrackDetails(completed: @escaping DownLoadComplete) {
Alamofire.request(trackURL).responseJSON { (response) in
if let dict = response.result.value as? [Dictionary<String, Any>] {
if let postcode = dict[0]["postcode"] as? String {
self._postcode = postcode
}
if let trackType = dict[0]["type"] as? String {
self._trackType = trackType
}
}
completed()
}
}
我的主屏幕上有多個項目,每個項目的ID都是1到8.當前我只能在運行時返回json字典中的第一個條目。我需要做些什麼才能讓它爲某個特定的ID拉數據。因此,如果我點擊ID爲1的第一個圖標,它將返回WR6的郵編6EW
什麼是您所遇到的具體問題,以獲得該項目? – Andreas
無論我在主屏幕上按哪個圖標我都會得到相同的結果,這是第一組數據,我需要它只提供匹配ID的數據集 –
您是否期望訪問除第一組以外的任何其他對象當你將索引硬編碼爲0時?你認爲'dict [0]'會做什麼? – Andreas