Data cannot be read because it isn' t 末尾的垃圾-6ren"> Data cannot be read because it isn' t 末尾的垃圾-所以这是我的网络请求。 //MARK:- 网络请求 let urlString = Constants.kBaseUrl + Constants.kEventsUrl Alamofire.reques-6ren">
gpt4 book ai didi

ios - iOS Swift 格式正确的 ."UserInfo={NSDebugDescription=Garbage at end ---> Data cannot be read because it isn' t 末尾的垃圾

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:57:06 25 4
gpt4 key购买 nike

所以这是我的网络请求。

//MARK:- 网络请求

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:- 以及我来自 postman 的 json 响应

 {
"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 block 并抛出错误

Error Domain=NSCocoaErrorDomain Code=3840 “最后是垃圾。” UserInfo={NSDebugDescription=最后是垃圾。})

在打印错误描述时,它返回“无法读取数据,因为它的格式不正确。”

这是我的网址:

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

这是所需的 header 键:

["校验和":"3389dae361af79b04c9c8e7057f60cc6"]

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

我不知道我错过了什么

有人请告诉我我错过了什么..

最佳答案

检查您的 Web 服务响应,它不是有效的 json,这就是您收到此类错误的原因。

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

在您的 postman json 响应末尾缺少一个括号“}”。

关于ios - iOS Swift 格式正确的 ."UserInfo={NSDebugDescription=Garbage at end ---> Data cannot be read because it isn' t 末尾的垃圾,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39831188/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com