【发布时间】:2014-09-07 16:18:49
【问题描述】:
感谢您检查这个问题。
这是我的问题,我正在尝试创建一个简单的 Google 翻译应用程序。我已经在 Google Console 中激活了它,所以我认为我的问题出在我的代码上。
返回的格式是
{ "数据": { "翻译": [ { "translatedText": "你好", "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 行上,我如何将返回类型设置为“作为字典”。响应比这要复杂一些,但我只是不确定如何设置它。
当我运行程序时,它会停在上面提到的行 (jsonResult) 并转到 swift_conformsToProtocol 设置
0x10c210572: nopw %cs:(%rax,%rax) 0x10c210580: movq %rax, -0x108(%rbp) 0x10c210587: xorps %xmm0, %xmm0
0x10c21058a: 移动 %xmm0, -0x70(%rbp)
0x10c21058e: movq $0x0, -0x60(%rbp) 0x10c210596: movq (%rdx), %rax 0x10c210599: cmpq $0x41, %rax
提前感谢您的帮助。
【问题讨论】:
-
我正在尝试在我的项目中使用您的代码,您将什么设置为 transURL?
标签: ios json swift google-translate