【发布时间】:2015-07-01 17:25:42
【问题描述】:
我的 JSON 结构如下。我对 Alamofire 和 SwiftyJSON 很陌生。在浏览了文档并修改了好几个小时后,我一直无法弄清楚如何解析这个 JSON 结构中的各个元素。
{
"transactions": {
"transaction": [
{
"payment_id": 2,
"payment_date": "2015-06-30",
"url": "myurl",
"title": "mytitle",
"sell_id": 4,
"last_update": "2015-06-30",
"inventory_id": 4,
"amount": "30.00",
"item_id": 4682,
"buyer_id": 1
},
{
"payment_id": 1,
"payment_date": "2015-06-29",
"url": "myurl2",
"title": "mytitle",
"sell_id": 3,
"last_update": "2015-06-29",
"inventory_id": 3,
"amount": "40.00",
"item_id": 1061,
"buyer_id": 1
}
]
}
}
代码:
class func RecentTransactions() {
Alamofire.request(.GET, requestURL)
.responseJSON { (_, _, jsonData, _) in
println(jsonData!)
let json = JSON(jsonData!)
}
}
【问题讨论】:
-
一个有助于简化 Json 阅读的库。 gist.github.com/Loki-Astari/5d36646cafe9044779eb
标签: json swift alamofire swifty-json