【发布时间】:2015-06-13 14:53:16
【问题描述】:
我目前正在尝试在 Xcode 中解码 Json,但我没有成功获得其中之一。
这就是我得到的:
[
{
"id": "1",
"title": "bmw",
"price": "500.00",
"description": "330",
"addedDate": "2015-05-18 00:00:00",
"user_id": "1",
"user_name": "CANOVAS",
"user_zipCode": "32767",
"category_id": "1",
"category_label": "VEHICULES",
"subcategory_id": "2",
"subcategory_label": "Motos",
"bdd": {}
}
"pictures":
[
{ "name": "http://cars.axlegeeks.com/sites/default/files/4315/media/images/2014_BMW_Z4_sDrive28i_3790993.jpg"
}
]
}
]
我想获取“图片”行的“名称”值,但出现错误“在展开值时意外发现 nil”。
对于其他值,我以这种方式进行:
let jsonData:NSDictionary = NSJSONSerialization.JSONObjectWithData(urlData!, options:NSJSONReadingOptions.MutableContainers , error: &error) as! NSDictionary
//Browse into JSON to get datas
let resp = jsonData["0"] as! NSDictionary
let user_nameR = resp["user_name"] as! String
let user_zipCodeR = resp["user_zipCode"] as! String
let titleR = resp["title"] as! String
let priceR = resp["price"] as! String
let descriptionR = resp["description"] as! String
感谢您的帮助!
【问题讨论】:
-
println(urlData!)你看到了什么? -
我已经将此控件放入我的代码中,我得到:urlData: 2063404224
-
这确实很有帮助。您能否使用 urlData 的完整值更新您的问题。
标签: json string swift nsdictionary