jsondecoder

JSONDecoder always returns “No value associated with key CodingKeys”

本秂侑毒 提交于 2019-12-02 05:48:48
I am using following decoding struct to decode the data from server but it always returns "No value associated with key CodingKeys". Please see the code below struct UserDecode: Codable { var user: User? var result: String? private enum CodingKeys: String, CodingKey { case user = "Records" case result = "Result" } init(from decoder: Decoder) throws { do { let values = try decoder.container(keyedBy: CodingKeys.self) result = try values.decode(String.self, forKey: .result) user = try values.decode(User.self, forKey: .user) } catch { print(error.localizedDescription) } } } struct User: Codable {

JSONDecodeError using Google Translate API with Python3

牧云@^-^@ 提交于 2019-11-27 15:41:37
I've searched thoroughly on Stack Overflow but couldn't find an answer to this problem. I'm trying to use the Google Translate API (googletrans 2.2.0) for Python (3.6.2) and am trying to translate a set of non-English documents into English. I am letting Google Translate do the language detection. Here is my code: ## newcorpus is a corpus I have created consisting of non-english documents fileids = newcorpus.fileids for f in fileids: p = newcorpus.raw(f) p = str(p[:15000]) translated_text = translator.translate(p) print(translated_text) sleep(10) I am throttling my call to the API by waiting