【发布时间】:2016-07-22 18:30:27
【问题描述】:
我是 iOS 编程的新手,我有一个关于 JSON 解析的小问题。
"data": [
{
"merchantId": "56",
"timings": [
[
"11:00 AM",
"11:00 PM"
]
],
"tags": [
"dine,north chinese"
],
"offers": [
{
"approvedBy": "56",
"locationId": "56",
"description": "Get 15% Off",
"finePrint": "• Cannot be combined with other offers.",
"audience": "all",
"status": "live",
"createdAt": "2016",
"updatedAt": "2016",
"offerType": "Discount",
"discount": "15",
"maxDiscount": 0,
"id": "56"
},
{
"approvedBy": "56023",
"locationId": "56023",
"description": "Get 25% Off",
"finePrint": "• Cannot be combined with other offers",
"audience": "all",
"status": "live",
"createdAt": "2016",
"updatedAt": "2016",
"hangoutId": "",
"offerType": "PercentDiscount",
"discount": "25",
"amount": 0,
"maxDiscount": 0,
"id": "5623"
},
};
我想下载上面的 JSON 数据,解析它并显示在标签中。 我可以使用以下代码下载并显示商家 ID:
let JSONRespone = response.result.value as? [String:AnyObject]
if JSONRespone != nil {
let datarray = JSONRespone!["data"] as? [[String:AnyObject]]
if datarray != nil {
for data in datarray! {
let anObject = SomeObject()
let merchantId = data["merchantId"] as? String
if merchantId != nil {
anObject.merchantidentity = merchantId!
}
如果我对计时和标签使用相同的代码,它不会显示任何内容。当我尝试在控制台中显示结果时,它显示“nil”。
除此之外,我如何在三个不同的标签中打印“优惠”中的“描述”。我只能打印所有这些中的一个。 有人可以帮我显示以下内容。提前致谢。
【问题讨论】: