如何从JSON数组SwiftyJSON获取数据?

时间:2016-02-25 21:27:55

标签: ios arrays json swifty-json

我希望能够从JSON数组中获取一些数据:here 所以下面,我试图显示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)")
}

1 个答案:

答案 0 :(得分:1)

date的{​​{1}}位于字典earliest的字典timeAdjustments

searchCriteria