最后是垃圾。UserInfo={NSDebugDescription=Garbage at end ---> 无法读取数据,因为它的格式不正确 iOS Swift



这是我的网络请求。

//标记:-网络请求

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]

//MARK:- and my json response from postman

 {
  "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 "Garbage at end."UserInfo={NSDebugDescription=结束垃圾})

打印错误描述时,返回"数据格式不正确,无法读取。"

这是我的url:

http://clients.view9.com.np/jwaremap/api/v1/content/events

这是必需的标头键:

("校验和":"3389 dae361af79b04c9c8e7057f60cc6")

在jsonlint.com上验证json结构时,它将其验证为有效的json。在使用。responsestring而不是。responsejson,我得到的结果。

我不知道我错过了什么

谁来告诉我我错过了什么

检查你的web服务响应,它不是一个有效的json,这就是为什么你得到这种错误。

尝试在这里查看您的json响应:- http://jsonviewer.stack.hu/

在您的postman json响应的末尾缺少一个"}"。

最新更新