こんにちは、これは私のjsonレスポンスです。どうすれば "data"パラメータ値をArrayに格納できますか?私はAlamofire 4とswift 3を使用しています。これは配列形式で、tableviewで内容をロードするために必要です。Alamofireを使用して辞書内のjsonオブジェクトを解析します。
Optional({
"current_page" = 2;
data = (
{
"address_location" = "place of course";
"category_id" = 1;
"course_id" = 122;
"course_title" = title;
description = "dessription about the course";
favorited = 0;
"from_date" = "2017-02-16";
image = "<path>";
lattitude = "0.876423656";
longitude = "6.86885314";
price = 200;
"subcategory_id" = 10;
thumb = "<path>";
"to_date" = "2017-02-16";
"user_id" = 32332;
},
{
"address_location" = "place of course";
"category_id" = 1;
"course_id" = 123;
"course_title" = title;
description = "dessription about the course";
favorited = 0;
"from_date" = "2017-02-16";
image = "<path>";
lattitude = "0.876423656";
longitude = "6.86885314";
price = 200;
"subcategory_id" = 10;
thumb = "<path>";
"to_date" = "2017-02-16";
"user_id" = 1;
}
);
message = Success;
"next_page" = 3;
"previous_page" = 1;
"status_code" = 200;
})
Alamofire.request(urlString, method: .get, parameters: ["":""], encoding: URLEncoding.default, headers: nil).responseJSON { (response:DataResponse<Any>) in
switch(response.result) {
case .success(_):
if response.result.value != nil{
print(response.result.value as Any)
//
self.parseData(JSONData: response.data!)
if let jsonDict = response.result.value as? [String:Any],
let dataArray = jsonDict["data"] as? [[String:Any]] {
self.dictionary_Course = dataArray as? [[String:Any]]
let nameArray = dataArray.flatMap { $0["address_location"] as? String }
print(nameArray)
}
print(self.dictionary_Course)
}
else
{
}
break
case .failure(_):
print(response.result.error as Any)
break
}
}
任意の値です。コードを追加できますか? – KKRocks