Hotenka // Deprecate NSJSONSerialization.
This commit is contained in:
parent
4184c3c1d2
commit
275288ea61
|
@ -100,9 +100,7 @@ public class HotenkaChineseConverter {
|
|||
dictFiles = .init()
|
||||
do {
|
||||
let rawData = try Data(contentsOf: URL(fileURLWithPath: jsonDir))
|
||||
guard let rawJSON: [String: [String: String]] = try JSONSerialization.jsonObject(with: rawData) as? [String: [String: String]] else {
|
||||
throw NSError()
|
||||
}
|
||||
let rawJSON = try JSONDecoder().decode([String: [String: String]].self, from: rawData)
|
||||
dict = rawJSON
|
||||
} catch {
|
||||
NSLog("// Exception happened when reading dict json at: \(jsonDir).")
|
||||
|
|
|
@ -40,7 +40,10 @@ extension HotenkaTests {
|
|||
let testInstance: HotenkaChineseConverter = .init(dictDir: testDataPath)
|
||||
NSLog("// Loading complete. Generating json dict file.")
|
||||
do {
|
||||
try JSONSerialization.data(withJSONObject: testInstance.dict, options: .sortedKeys).write(to: URL(fileURLWithPath: testDataPath + "convdict.json"))
|
||||
let urlOutput = URL(fileURLWithPath: testDataPath + "convdict.json")
|
||||
let encoder = JSONEncoder()
|
||||
encoder.outputFormatting = .sortedKeys
|
||||
try encoder.encode(testInstance.dict).write(to: urlOutput, options: .atomic)
|
||||
} catch {
|
||||
NSLog("// Error on writing strings to file: \(error)")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue