这是我的网络请求。
//标记:-网络请求
let urlString = Constants.kBaseUrl + Constants.kEventsUrl
Alamofire.request(.GET, urlString, parameters: nil, encoding: .JSON, headers: [Constants.kChecksum:Constants.kChecksumValue]) .responseJSON { response in
guard response.result.isSuccess else {
let alertController = UIAlertController(title:"Error", message:response.result.error?.localizedDescription, preferredStyle:UIAlertControllerStyle.Alert)
let okAction = UIAlertAction(title: "Cancel", style: .Cancel, handler: { action in
self.isFetchingEvents = false;
self.eventsFetchError = response.result.error
self.eventsTableView.reloadData()
})
let retryAction = UIAlertAction(title: "Retry", style: .Default, handler: { action in
self.downloadEvents()
})
alertController.addAction(okAction)
alertController.addAction(retryAction)
self.presentViewController(alertController, animated: true, completion: nil);
return
}
let tempInfo = response.result.value![Constants.kData] as! [AnyObject]//马克:-邮递员的回复
{
"success": 1,
"message": "Successful",
"data": [
{
"id": "196",
"title": "Arusha Christmas Fair 2016",
"body": null,
"field_events_date_from": "2016-12-24",
"field_events_date_to": "2016-12-25",
"field_events_time_from": "2016-10-03 13:56",
"field_events_time_to": "2016-10-03 21:57",
"image": "http://clients.view9.com.np/jwaremap/sites/default/files/events/2250x3324-christmas-fair_0.png",
"image-thumbnail": "http://clients.view9.com.np/jwaremap/sites/default/files/styles/thumbnail/public/events/2250x3324-christmas-fair_0.png?itok=U2W8DgA-",
"image-medium": "http://clients.view9.com.np/jwaremap/sites/default/files/styles/medium/public/events/2250x3324-christmas-fair_0.png?itok=ZZlYlC6L",
"image-large": "http://clients.view9.com.np/jwaremap/sites/default/files/styles/large/public/events/2250x3324-christmas-fair_0.png?itok=-vZhcEag",
"image-providercategory_threex": "http://clients.view9.com.np/jwaremap/sites/default/files/styles/providercategory-threex/public/events/2250x3324-christmas-fair_0.png?itok=hwpr3WQd",
"field_events_location": {
"lat": "-3.416825167067",
"lon": "36.657226562500"
},
"field_events_address": "TGT Grounds",
"field_events_email": "info@arushafair.com",
"field_events_contact": null,
"field_events_website": "www.arushafair.com",
"field_trip_advisor": null,
"field_facebook": "https://web.facebook.com/events/681411865357050/",
"field_twitter": null,
"field_youtube": "https://www.youtube.com/watch?v=_Pvisfxe6CA",
"field_info": "The ARUSHA COMMUNITY CHRISTMAS FAIR is the most anticipated holiday shopping and family fun event of the year -- hosting over 125 vendors and artisans from across East Africa and 5,000 visitors enjoying local talent, Arusha's best food and drink, lots of activities for the kids, and the chance to take home great prizes in the fantastic raffle and silent auction."
}
],
"author": {
"name": "superadmin",
"field_user_phone": "",
"field_user_address": {
"lat": "",
"lon": "",
"address": ""
},
"modified_date": "1475475942"
},
"total_items": 1,
"last_update": "1475475942"
}但是,它总是进入else块并抛出错误。
Error Domain=NSCocoaErrorDomain Code=3840“垃圾堆在尽头”。UserInfo={NSDebugDescription=Garbage at end.})
在打印错误描述时,它返回“由于数据格式不正确而无法读取”。
这是我的网址:
http://clients.view9.com.np/jwaremap/api/v1/content/events
这是所需的头键:
"checksum":"3389dae361af79b04c9c8e7057f60cc6"
在使用jsonlint.com验证json结构时,它将其验证为有效的json。关于使用.responseString而不是.responseJSON,我得到了结果。
我不知道我错过了什么
谁能告诉我我错过了哪里..。
发布于 2016-10-03 12:10:22
检查您的web服务响应--这不是一个有效的json,这就是为什么您会收到这样的错误。
尝试在这里查看您的json响应:- http://jsonviewer.stack.hu/
在您的邮递员json回复的末尾,有一处遗漏了“}”。
https://stackoverflow.com/questions/39831188
复制相似问题