![](/img/trans.png)
[英]How to remove an item from JSON array in Swift (using SwiftyJSON)
[英]Add elements from SwiftyJSON to URL array in Swift
我正在使用Alamofire檢索URL圖像列表。 響應是在JSON中,並且我使用了SwiftyJSON來解析和打印每個元素。 我希望將URL添加到URL數組中。 以下是我使用的代碼
var newArray = [URL(string: "http://www.tummyvision.com/users/uploads/gijovarghese141@gmail.com/photos/4.jpg")]
Alamofire.request("http://www.tummyvision.com/users/login/get-images.php", parameters: parameters).responseData { response in
let json = JSON(data: response.result.value!)
for i in 0..<json.count
{
print(json[i]) // prints the correct url
self.urlArray.append(json[i])
}
}
但這給了我以下錯誤:
嘗試使用arrayValue
JSON的屬性來訪問數組也需要轉換String
的URL URL
加入到它的前陣對象URL
。
if let urls = json.arrayValue {
for url in urls {
self.urlArray.append(URL(string:url))
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.