如何在SWIFT中从JSON数组中获取内部值

时间:2016-02-17 20:20:45

标签: arrays json swift

我想从JSON数组中获取statusSeverityDescription值,我能够得到第一部分,但我无法解决任何内容

这是数组:https://api.tfl.gov.uk/line/mode/tube/status

func parseJSONtubes() {  
    let url = NSURL(string: "https://"
    let jsonData = NSData(contentsOfURL: url!)  
    let readableJSON = JSON(data: jsonData!, options: NSJSONReadingOptions.MutableContainers, error: nil)  


    for (_,object):(String, JSON) in readableJSON {  
        /  
        let stationName = object["name"].string as String!  
        let statusName = object[0]["lineStatuses"]    ["statusSeverityDescription"].string as String!  
        stationArray.append(stationName)  
        statusArray.append(statusName)  
        /  
        NumberOfRows = stationArray.count  

    }  
    NSLog("\(NumberOfRows)")  
    NSLog("\(stationArray)")  


}

我在这里做错了...... statusName没有显示任何内容?!

1 个答案:

答案 0 :(得分:0)

这是

...
   let stationName = object["name"].stringValue
   let statusName = object["lineStatuses"][0]["statusSeverityDescription"].stringValue
...