gpt4 book ai didi

ios - Swift:谷歌翻译格式失败

转载 作者:行者123 更新时间:2023-11-28 07:16:29 25 4
gpt4 key购买 nike

感谢您检查这个问题。

这是我的问题,我正在尝试创建一个简单的 Google 翻译应用程序。我已经在 Google 控制台中激活了它,所以我认为我的问题出在我的代码上。

返回的格式是

{ "data": { "translations": [ { "translatedText": "bonjour", "detectedSourceLanguage": "en" } ] } }

我的代码是这样设置的:

var session = NSURLSession.sharedSession()

var task = session.dataTaskWithURL(transURL){
data, response, error -> Void in
NSLog("dkc 1")
if(error != nil){
println(error.localizedDescription)
}

var jsonError : NSError?
NSLog("dkc 2")
var jsonResult = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers, error: &jsonError) as Dictionary<String, String>
NSLog("dkc 2.5"
if (jsonError? != nil){
println(jsonError!.localizedDescription)
}
NSLog("dkc 3")
if let apiDelegate = self.delegate?{

dispatch_async(dispatch_get_main_queue()){
NSLog("dkc 4")
apiDelegate.didFinishGTTranslation(jsonResult)
}

}

抱歉格式不正确...我不确定,但我认为问题出在 var jsonResult 行上,我如何将返回类型设置为“as Dictionary”。响应比这复杂一点,但我只是不确定如何设置它。

当我运行程序时,它停在上面提到的行 (jsonResult) 并转到 swift_conformsToProtocol 设置

0x10c210572: nopw %cs:(%rax,%rax)0x10c210580: movq %rax, -0x108(%rbp)0x10c210587: xorps %xmm0, %xmm0

0x10c21058a: movaps %xmm0, -0x70(%rbp)

0x10c21058e: movq $0x0, -0x60(%rbp)0x10c210596: movq (%rdx), %rax0x10c210599: cmpq $0x41, %rax

在此先感谢您的帮助。

最佳答案

您将顶级 JSON 对象转换为 <String:String>而实际上它是 <String:AnyObject> ,您的顶级词典的值(value)是另一本词典。

关于ios - Swift:谷歌翻译格式失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25712328/

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