-2
我有一個代碼來使用REST服務,但它停止更新後的工作,以SWIFT 2.3和iOS 10. 我得到錯誤的JSON到NSMutableArray的轉換:JSON來的NSMutableArray停止雨燕2.3的iOS工作10
class func getStores(latitude:Float, longitude: Float, completion : (Array<Store>?, NSError?) ->()) {
let latString: String = "\(latitude)"
let lonString: String = "\(longitude)"
var listStores: Array<Store> = []
let urlFull : String = ConstantHelper.baseURLStore
Alamofire.request(.GET, urlFull, parameters: ["latitude":latString, "longitude": lonString])
.responseJSON { response in
switch response.result {
case .Success:
if let repoJSON = response.result.value {
print(repoJSON)
let jsonArray = repoJSON as? NSMutableArray
for item in jsonArray! {
guard let store = Store(json: item as! JSON) else
{
print("Issue deserializing model")
return
}
listStores.append(store)
}
completion(listStores, nil)
}
break
case .Failure(let error):
completion(nil, error)
break
}
}
}
編輯:
錯誤是「致命錯誤:意外地發現零而展開的可選值」
這意味着該變量jsonArray是零。但它的零點只有在2.3。因爲轉換json到NSMutableArray不起作用。我需要改變我轉換的方式......但如何?
還有的repoJSON值
(
{
cdState = SP;
cdStore = 100;
cdZipCode = "04029200 ";
mnStore = IBI;
noAddress = "AV IBIRAPUERA,";
noAddressAditional = " 3103 - LOJAS 4-5";
noAddressNeighborhood = " 3103";
noCity = "S\U00e3o Paulo ";
noStore = "IBI-M-C-SHOPPING IBIRAPUERA";
vlLatitude = "-23.610113";
vlLongitude = "-46.666505";
},
{
cdState = SP;
cdStore = 105;
cdZipCode = "05724900 ";
mnStore = JSU;
noAddress = "AV GIOVANNI GRONCHI, 5819 - LUC001";
noAddressAditional = "<null>";
noAddressNeighborhood = "VILA ANDRADE";
noCity = "S\U00e3o Paulo ";
noStore = "JSU-C-C-SHOPPING JARDIM SUL";
vlLatitude = "-23.630835";
vlLongitude = "-46.7359";
},
{
cdState = SP;
cdStore = 107;
cdZipCode = "05145000 ";
mnStore = TTE;
noAddress = "AV. RAIMUNDO PEREIRA DE MAGALH\U00c3ES, 1465 \U0096 LOJA \U00c2NCORA 1000";
noAddressAditional = "<null>";
noAddressNeighborhood = "JD \U00cdRIS";
noCity = "S\U00e3o Paulo ";
noStore = "TTE-PP-C-SHOPPING TIET\U00ca PLAZA";
vlLatitude = "-23.506182";
vlLongitude = "-46.718449";
},
{
cdState = SP;
cdStore = 115;
cdZipCode = "03153001 ";
mnStore = CEN;
noAddress = "AV.DR.FRANCISCO MESQUITA, 1000";
noAddressAditional = "<null>";
noAddressNeighborhood = "VILA PRUDENTE";
noCity = "S\U00e3o Paulo ";
noStore = "CEN-PP-C-CENTRAL PLAZA SHOPPING";
vlLatitude = "-23.593389";
vlLongitude = "-46.585574";
}
)
爲什麼不更新你的問題與錯誤的具體細節?包括確切的完整錯誤信息並指出導致錯誤的確切行。 – rmaddy