How to send dictionary datatype object over a socket? I know from Python 3, we have to use encode() and decode() while sending and receving a string through a socket, like socket.send(data.encode()) and socket.recv(data.decode())
. How are we supposed the same thing for dictionary?
Asked
Active
Viewed 438 times
0

Apoorva Somani
- 515
- 1
- 6
- 23
1 Answers
0
I think you can use:
serialized_dictionary = json.dumps(your_dictionary)
your_dictionary=json.loads(serialized_dictionary)
Don't forget to import json module:
import json
Hope this helps! =)

jlnabais
- 829
- 1
- 6
- 18
-
Found a similar question (check this too): http://stackoverflow.com/questions/15190362/sending-a-dictionary-using-sockets-in-python – jlnabais Sep 11 '15 at 20:49