【发布时间】:2016-04-12 16:47:53
【问题描述】:
当我要在我的设备上运行我的应用程序时,我的 swift 代码出现问题。当我在模拟器上运行它时一切都很好,但是当我要在我的设备上运行它时出现两个错误。
最后两行出现两个错误,两行都显示“下标使用不明确”。
如果需要帮助,我正在运行最新的 xcode...
let requestURL: NSURL = NSURL(string: "The webpage im getting info from")!
let urlRequest: NSMutableURLRequest = NSMutableURLRequest(URL: requestURL)
let session = NSURLSession.sharedSession()
let task = session.dataTaskWithRequest(urlRequest) {
(data, response, error) -> Void in
let httpResponse = response as! NSHTTPURLResponse // method that access information
let statusCode = httpResponse.statusCode
if (statusCode == 200) {
do{
let json = try NSJSONSerialization.JSONObjectWithData(data!, options:.AllowFragments)
// naming the two variables from json
if let counter = json["counts"] {
// It gets an error on both the peopleIn and peopleOut
let peopleIn = counter! [0]
let peopleOut = counter! [1]
【问题讨论】:
-
我希望计数器即 json["counts"] 是一个正确的数组结构。