2 jeffguan jeffguan 于 2016.09.15 08:56 提问

swift 3.0 中网络数据解析错误,求指导

图片说明

2个回答

oyljerry
oyljerry   Ds   Rxr 2016.09.15 11:02

用jsonobject类型试试

mengxinyizhui
mengxinyizhui   2016.10.10 10:12

let listUrlString = "http://bla.com?batchSize=" + String(batchSize) + "&fromIndex=" + String(fromIndex)
let myUrl = URL(string: listUrlString);
var request = URLRequest(url:myUrl!)
request.httpMethod = "GET";

let task = URLSession.shared().dataTask(with: request as URLRequest)) {
data, response, error in

    if error != nil {
        print(error!.localizedDescription)
        DispatchQueue.main.sync(execute: {
            AWLoader.hide()
        })

        return
    }

    do {

        let json = try JSONSerialization.jsonObject(with: data!, options: .mutableContainers) as? NSArray

        if let parseJSON = json {

            var items = self.categoryList

            items.append(contentsOf: parseJSON as! [String])

            if self.fromIndex < items.count {

                self.categoryList = items
                self.fromIndex = items.count

                DispatchQueue.main.async(execute: {

                    self.categoriesTableView.reloadData()

                    AWLoader.hide()

                })
            }else if( self.fromIndex == items.count){


                DispatchQueue.main.async(execute: {

                    AWLoader.hide()

                })

            }



        }

    } catch {
        AWLoader.hide()
        print(error)

    }
}

task.resume()
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!