我看了一下其他問題,但似乎找不到能解答我的問題的問題。使用SwiftyJSON和Alamofire循環瀏覽JSON
我有這個JSON文件:
[
"posts",
{
"2015": [
"post title one"
],
"2016": [
"post title one",
"post title two"
]
}
]
,我有這樣的代碼在我的雨燕文件:
Alamofire.request(.GET, url).validate().responseJSON { response in
switch response.result {
case .Success:
if let value = response.result.value {
let json = JSON(value)
for (key, subJson) in json["posts"] {
if let year = subJson.string {
print(year)
}
}
}
case .Failure(let error):
print(error)
}
}
我可以從服務器獲取ok了JSON。
在此行中:
for (key, subJson) in json["posts"] {
我得到這個錯誤:
immutable value 'key' was never used, consider replaying with '_' or removing it
我試過了,並試圖消除它 - 仍然沒有顯示在控制檯中。
而且,在這條線:
if let year = subJson.string {
我得到這個錯誤:
Value of tuple type 'Element' (aka '(String, JSON)') has no member 'string'
我想要做的是這樣的:
遍歷所有這些年來,把他們在一個可用視圖。有人可以幫忙嗎?
應如何JSON看?我用PHP來生成它,所以也許我做錯了.. – JamesG
Gunna現在嘗試你的解決方案。 – JamesG
我得到了不可改變的值'內容'從來沒有使用過,請考慮用'_'重放或刪除它 – JamesG