我的API中有这样的JSON响应:
SUCCESS: {
data = (
{
addressDescription = "";
addressLine1 = "30 xxx Street";
addressLine2 = xxx;
addressLine3 = "";
addressType = 1;
city = Lagos;
country = Nigeria;
id = xxx;
state = Lagos;
},
{
addressDescription = "AAA";
addressLine1 = "11 bbb Street,";
addressLine2 = "Ikeja";
addressLine3 = "";
addressType = 1;
city = Lagos;
country = Nigeria;
id = xxx;
state = Lagos;
}
);
我的Swift代码如下所示:
var productsArray = [AnyObject]()
Alamofire.request(URL).responseJSON {
response in
//printing response
print(response)
//getting the json value from the server
let result = response.result
if let dict = result.value as? Dictionary<String,AnyObject> {
if let innerDict = dict["data"]{
self.addyArray = innerDict as! [AnyObject]
}
}
}
如何获取此数组中的各个字段(addressLine1,addressLine2等)以显示在我的UIPickerView中?任何帮助将不胜感激。
答案 0 :(得分:0)
您可以使用此keys
从Dictionary
获取所有self.addyArray.first.keys //return array of keys
。
self.addyArray[0].keys //return array of keys
或
class MyCell: FSPagerViewCell{
}
确保您的阵列不为空。
答案 1 :(得分:-1)
假设你按照上面提到的json结构正确得到了结果。
filename = forms.FileField(label='Select a file')
答案 2 :(得分:-1)
Alamofire.request(URL).responseJSON {
response in
//printing response
print(response)
//getting the json value from the server
let result = response.result
if let dict = result.value as? Dictionary<String,AnyObject> {
if let innerDict = dict["data"]{
for val in 0..<innerDict.count {
let dic = innerDict as! [String, AnyObject]
for vals in dic {
print(vals)
productsArray.append(vals)
}
}
}
}
}