我试图读取json数据并返回" false"

时间:2015-11-17 20:09:56

标签: json nsarray nsurl jsonobject

这是我的代码返回false而不是json数组计数。 我必须评论说,它一度有效,然后停止了。请帮忙。

            let task = NSURLSession.sharedSession().dataTaskWithURL(url!, completionHandler: { (data, response, error) -> Void in

                let urlError = false

                if error == nil {

                    let urlContent = NSString(data: data!, encoding: NSUTF8StringEncoding) as NSString!

                    let data: NSData = urlContent.dataUsingEncoding(NSUTF8StringEncoding)!

                    print("data here\(data)”) // I see a lot of data in the logs with this print

                    do {

                        let jsonObject = try (NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers) as? NSArray)!

                    print(“here is the array count\(jsonObject.count)”) // it never prints this to the logs. What I get is “false"

                    …The rest of the code...

0 个答案:

没有答案