[英]Cannot convert value of type 'String?.Type' to expected argument type 'String?'
[英]Cannot convert value of type '(String, JSON)' to expected argument type '[JSONSubscriptType]'
我試圖遍歷一組帖子並通過遍歷圖像計數來獲取他們的媒體。
這不起作用 - images
被設置為0
for images in JSON(response.value!)["post"]["media"] {
print(JSON(response.value!)["post"]["media"][images]["image_url"])
}
但這確實
for images in JSON(response.value!)["post"]["media"] {
print(JSON(response.value!)["post"]["media"][0]["image_url"])
}
我得到的錯誤是
Cannot convert value of type '(String, JSON)' to expected argument type '[JSONSubscriptType]'
似乎使用循環中的變量不起作用,但直接 Int 起作用。 我也試過將images
包裝為Int
工作代碼顯示關鍵media
的對象是一個字典數組。
所以在循環中images
(實際上是image
)代表每次迭代中陣列media
一項。
假設JSON
與SwiftyJSON
相關—— SwiftyJSON
,它已經過時而支持Codable
你必須編寫
for image in JSON(response.value!)["post"]["media"].arrayValue {
print(image["image_url"])
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.