Skip to content

Commit

Permalink
fix: proper json decoding
Browse files Browse the repository at this point in the history
  • Loading branch information
Jerry23011 committed Dec 1, 2023
1 parent 0bc3e11 commit 2e7b55f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
12 changes: 8 additions & 4 deletions Easydict/Feature/Service/Tencent/TencentResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@
import Foundation

struct TencentResponse: Codable {
var RequestId: String
var Source: String
var Target: String
var TargetText: [String]
struct Response: Codable {
var RequestId: String
var Source: String
var Target: String
var TargetText: String
}

var Response: Response
}
5 changes: 2 additions & 3 deletions Easydict/Feature/Service/Tencent/TencentService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public final class TencentService: QueryService {
let projectId: Int64 = 0

let parameters: [String: Any] = [
"SourceText": "\(text.split(separator: "\n"))",
"SourceText": text,
"Source": transType.sourceLanguage,
"Target": transType.targetLanguage,
"ProjectId": projectId,
Expand Down Expand Up @@ -182,7 +182,6 @@ public final class TencentService: QueryService {
parameters: parameters,
encoding: JSONEncoding.default,
headers: headers)

.validate()
.responseDecodable(of: TencentResponse.self) { [weak self] response in
guard let self else { return }
Expand All @@ -192,7 +191,7 @@ public final class TencentService: QueryService {
result.from = from
result.to = to
result.queryText = text
result.translatedResults = value.TargetText
result.translatedResults = value.Response.TargetText.components(separatedBy: "\n")
completion(result, nil)
case let .failure(error):
NSLog("Tencent lookup error \(error)")
Expand Down

0 comments on commit 2e7b55f

Please sign in to comment.