【问题标题】:Ambiguous use of subscript error while trying to build app on an actual device尝试在实际设备上构建应用程序时使用不明确的下标错误
【发布时间】:2017-01-25 05:01:18
【问题描述】:

我正在尝试在真实设备(iPhone 7 plus)上构建我的应用程序。我的应用程序在模拟器上运行得很好,但是当我尝试在真实设备上构建它时,它给了我 2“Ambiguous use of subscript errors”。

let url = URL(string: "https://api.cognitive.microsoft.com/bing/v5.0/news/search?q=\(feedsArray[i])&count=3&mkt=en-in")
        var request = URLRequest(url: url!)
        request.setValue("MY SUBSCRIPTION KEY", forHTTPHeaderField: "Ocp-Apim-Subscription-Key")

        Alamofire.request(request as URLRequest).responseJSON {response in

            if let json = response.result.value as? [String:AnyObject]{


                if let value = json["value"]{

                    //
                    print("json \(json)")

                    for j in 0..<value.count{

                        let items = value[j] as! [String: AnyObject]

                        let name = items["name"] as! String

                        let url = items["url"] as! String



                        let description = items["description"] as! String

                        let datePublished = items["datePublished"] as! String

                        let dateAndTime = datePublished.replacingOccurrences(of: "T", with: " ")

我在行中有错误

     let items = value[j] as! [String: AnyObject]

【问题讨论】:

    标签: ios arrays json swift string


    【解决方案1】:

    我认为json["value"]Dictionary,这就是为什么你尝试用value[j] 下标时出错的原因,如果你想像下标一样,你可能想把它转换为Array

    if let value = json["value"] as! [[String: Any]]

    【讨论】:

    • @NiravD 我也是这么说的?
    • 感谢您的意见
    猜你喜欢
    • 2023-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-09
    • 2020-05-08
    • 1970-01-01
    相关资源
    最近更新 更多