SwiftyJSON - 解析问题

时间:2015-10-14 11:18:43

标签: ios swift swifty-json

我尝试使用SwiftyJSON解析json。其中一个字段有url to image,我尝试将其保存为NSData但我遇到崩溃和控制台错误。编译器进入对象创建时出现崩溃

将其编码为以下

var JSONStorage : [Article?]?
var objects = [Article?]()

override func viewDidLoad() {
    super.viewDidLoad()

    let number = arc4random_uniform(1000)
    let urlString = "http://wirehead.ru/article.json?\(number)"

    if let url = NSURL(string: urlString) {
        if let data = try? NSData(contentsOfURL: url, options: []) {
            let json = JSON(data: data)

            for element in json["article"].arrayValue {

                let id = Int(element["id"].stringValue)
                let title = element["title"].stringValue
                let subtitle = element["subtitle"].stringValue
                let body = element["body"].stringValue
                let img = element["images"]["main"].rawValue
                let obj:Article = Article(id: id!, title: title, subtitle: subtitle, body: body, mainImage: img as! NSData)

                objects.append(obj)
                print("We are inside if let")

            }

        }
    }

    print(objects)

}

JSON链接为http://wirehead.ru/article.json,此处为高亮显示http://pastebin.com/AAEFjsQN

我得到的错误是

enter image description here

有什么建议吗?

1 个答案:

答案 0 :(得分:2)

In [5]: df['B&C'] = np.where(df.B.isnull() & df.C.isnull(), 'Not There', 'Present') In [6]: df['B&C'] Out[6]: 0 Present 1 Not There 2 Present 3 Present Name: B&C, dtype: object 包含由["images"]["main"]

表示的网址

要获取图像数据,请使用类似

的内容
String