gpt4 book ai didi

ios - 以 10 : in swift 2 为基数的 int () 的无效文字面临错误

转载 作者:行者123 更新时间:2023-11-29 11:47:11 24 4
gpt4 key购买 nike

enter image description here

根据屏幕截图,同时提交面临此问题的反馈。感谢您的帮助。

输入一些关于旅程的文字后,我必须输入微笑或悲伤之类的评论。一切正常。当我点击提交按钮时,我得到的 journeyIdnil 而不是 self.journeyAPIdetails 我从 JSON 获取全部数据。提前致谢。

 func submitButtonTapped() {

if self.smileActive! == true || self.frownActive! == true {

let comment = (self.mainView.textfield.text! == "Tap to Type" || self.mainView.textfield.text! == "Leave any additional Comments here") ? "": self.mainView.textfield.text!

let rating = self.smileActive! == true ? "true":"false"

let journeyId = self.journeyAPIdetails!["data"]["journey_id"].stringValue
let userId = AccountService.sharedInstance.typeOfUser() == .Customer ? self.journeydetails?.driver.id : self.journeydetails?.customer.id


let details = ["rating":rating, "comment":comment, "journey_id":journeyId]

JourneyService().rateAUser(details).onSuccess { (json) -> Void in

if json["status"].stringValue == "success" {
print("dismissViewControllerAnimate")
self.dismissViewControllerAnimated(true, completion: nil)
AccountService.sharedInstance.clearJourneyContent()

} else if json["status"].stringValue == "fail" {

print("dismissViewControllerAnimated")

self.displayAlert("Error", message: json["message"].stringValue)
}
}
}

else {
super.displayAlert("Feedback", message: "Give some feedback and optionally add some comments.")
}
}
}

最佳答案

invalid literal for int () with base 10: '' 是来自 Python 的错误消息,指示您要将空字符串转换为整数。这意味着服务器需要一个包含十进制数字的字符串,但您却给它一个空字符串。这表明 details 输入错误,尤其是 journeyId 字段。

discussing with OP 之后,我们发现问题出在 self.journeyAPIdetails!["data"] 中:它是一个包含单个对象的数组,但 OP 没有注意到它。所以解决方案是将该行更改为:

let journeyId = self.journeyAPIdetails!["data"][0]["journey_id"].stringValue
// ^^^

故事的寓意:仔分割析您发送和接收的 JSON 的结构。

关于ios - 以 10 : in swift 2 为基数的 int () 的无效文字面临错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43071019/

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