Reputation: 83
I would like to be able to get some data from a JSON array: here so below, I am trying to show EARLIEST > DATE
func parseJSONtowns() {
let url = NSURL(string: "https://api.tfl.gov.uk/journey/journeyresults/\(selectedStation)/to/\(selectedStation1)")
let jsonData = NSData(contentsOfURL: url!)
let readableJSON = try! NSJSONSerialization.JSONObjectWithData(jsonData!, options: []) as! [String:AnyObject]
let object = JSON(readableJSON)
let searchCriteria = object["earliest"]
for option in searchCriteria.arrayValue {
let commonName = option["date"].stringValue
commonNameArray.append(commonName)
}
selectedStation = selectedStation.stringByReplacingOccurrencesOfString("%20", withString: " ")
NumberOfRows = commonNameArray.count
NSLog("\(url)")
NSLog("number of rows: \(NumberOfRows)")
}
Upvotes: 0
Views: 301
Reputation: 285064
The date
of earliest
is in a dictionary timeAdjustments
in a dictionary searchCriteria
let object = JSON(readableJSON)
let earliest = object["searchCriteria"]["timeAdjustments"]["earliest"]["date"].stringValue
print(earliest)
Upvotes: 1