decode

Swift - Encode and Decode a dictionary [String:Any] into plist

耗尽温柔 提交于 2020-02-16 07:29:07
问题 I am trying to store the dictionary in my class Marker but it is throwing an error saying it is not encodable or decodable. I can see the error is caused by the [String: Any] but how can I go around it? var buttonActions : [String: [String: [String:Any]]] = [:] Save and Load func saveData() { let dataFilePath = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first?.appendingPathComponent("\(fileName).plist") let encoder = PropertyListEncoder() do { let data = try

Python乱码、编码问题汇总

ぐ巨炮叔叔 提交于 2020-02-14 16:36:29
为什么Python使用过程中会出现各式各样的乱码问题,明明是中文字符却显示成“\xe4\xb8\xad\xe6\x96\x87”的形式? 为什么会报错“U nicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128)”?本文就来研究一下这个问题。 字符串在Python内部的表示是unicode编码,因此,在做编码转换时,通常需要以unicode作为中间编码,即先将其他编码的字符串解码(decode)成unicode,再从unicode编码(encode)成另一种编码。 decode的作用是将其他编码的字符串转换成unicode编码,如str1.decode('gb2312'),表示将gb2312编码的字符串str1转换成unicode编码。 encode的作用是将unicode编码转换成其他编码的字符串,如str2.encode('gb2312'),表示将unicode编码的字符串str2转换成gb2312编码。 因此, 转码的时候一定要先搞明白,字符串str是什么编码,然后decode成unicode,然后再encode成其他编码 代码中字符串的默认编码与代码文件本身的编码一致。 如:s='中文' 如果是在utf8的文件中

2.8连接数据库中遇见的相应问题2

假如想象 提交于 2020-02-09 12:48:15
django连接mysql报错'str' object has no attribute 'decode' 出现这个错误之后可以根据错误提示找到文件位置,打开 operations.py 文件,找到以下代码: 根据错误信息提示,说明 if 语句执行时出错, query 是 str 类型,而 decode() 是用来将 bytes 转换成 string 类型用的, (关于Python编码点这里) ,由于 query 不需要解码,所以直接将 if 语句注释掉就可以了 来源: https://www.cnblogs.com/y862621115/p/12286641.html

Decoding/Encoding a struct with protocol type properties

谁说胖子不能爱 提交于 2020-02-06 08:08:14
问题 I am trying to save a configuration data structure with UserDefaults , thus the data structure needs to conform to the Codable protocol. This is my data structure: // Data structure which saves two objects, which conform to the Connection protocol struct Configuration { var from: Connection var to: Connection } protocol Connection: Codable { var path: String { get set } } // Two implementations of the Connection protocol struct SFTPConnection: Connection, Codable { var path: String var user:

Read raw IPv4 in promiscuous mode on Linux?

别等时光非礼了梦想. 提交于 2020-02-06 02:57:47
问题 I am trying to write an application to sniff traffic being sent to an ethernet port on my server. My application never needs to send data. It only needs to receive and decode the 5-tuple. I am opening the socket with: socket (AF_INET, SOCK_RAW, htons (ETH_P_ALL)) and setting it to promiscuous mode: struct ifreq ifr; ioctl (raw_socket, SIOCGIFFLAGS, &ifr); /* Set the old flags plus the IFF_PROMISC flag */ ifr.ifr_flags |= IFF_PROMISC; ioctl (raw_socket, SIOCSIFFLAGS, &ifr); I am using recv to

Read lines of a textfile and getting charmap decode error

笑着哭i 提交于 2020-02-02 11:43:06
问题 im using python3.3 and a sqlite3 database. I have a big textfile around 270mb big which i can open with WordPad in Windows7. Each line in that file looks as follows: term \t number\n I want to read every line and save the values in a database. My Code looks as follows: f = open('sorted.de.word.unigrams', "r") for line in f: #code I was able to read all data into my database but just to a certain line, i would suggest maybe half of all lines. Then im getting the following error: File "C:

node.js报Decode error - output not utf-8]错误

守給你的承諾、 提交于 2020-02-01 18:13:24
找到Nodejs文件夹下的Nodejs.sublime-build文件 找到对应代码修改为一下 "windows": { // "shell_cmd": "taskkill /F /IM node.exe & node $file" "cmd":["D:/application/NodeJs/node.exe","$file"], "selector":"*.js" }, 其中"D:/application/NodeJs/"为node.js安装位置,在其后加node.exe即可 来源: CSDN 作者: 笑看浮尘 链接: https://blog.csdn.net/XKFC1/article/details/104135783

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xcc in position 53: invalid continuation byte报错

筅森魡賤 提交于 2020-02-01 02:00:36
报UnicodeDecodeError: ‘utf-8’ codec can’t decode byte 0xcc in position 53: invalid continuation byte错误解决方法 # 在decode的第二个参数中加入“ignore” decode ( "utf-8" , "ignore" ) decode的函数原型是decode([encoding], [errors=‘strict’]), 第二个参数控制错误处理的策略,默认的参数就是strict,代表遇到非法字符时抛出异常; 设置为ignore,则会忽略非法字符; 设置为replace,则会用?取代非法字符; 设置为xmlcharrefreplace,则使用XML的字符引用。 来源: CSDN 作者: CesareCheung 链接: https://blog.csdn.net/weixin_42760923/article/details/103914455

Handling different types when unmarshalling a json [duplicate]

跟風遠走 提交于 2020-01-30 06:57:49
问题 This question already has answers here : unmarshal nested json without knowing structure (2 answers) Closed 11 months ago . I'm consuming an endpoint (which I don't own and I cannot fix) and this endpoint returns JSON. The problem is this JSON can come in different formats: Format 1: { "message": "Message" } or { "message": ["ERROR_CODE"] } Depending on what happened. I'd like to have one struct to hold this response so later I can check if the message is a string or array, and properly

decoding eval(base64_decode))

[亡魂溺海] 提交于 2020-01-30 04:05:55
问题 I am trying to decode this code. I know it can be done by changing eval to echo. But in this case its not working. Is i am making any mistake. This is my encoded_file.php code: i have tried to change eval to echo but its not working file. I also tried this decoder: <?php // Open and read the content of the encoded file into a variable $file = file_get_contents('encoded_file.php'); // Strip php tags $file = str_replace('<?php', "", $file); $file = str_replace('<?', "", $file); // Make sure to