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