I'm running into an issue with parsing JSON data into a dict which I cannot figure out.
I'm connecting to a Tornado websocket from JavaScript and sending the following data, entered into a textfield:
{"action": "something"}
The way I'm sending it to the websocket is:
sock.send( JSON.stringify( $('textfield').value ) );
Now in Python I have the following code in my WebsocketHandler::on_message():
print("Message type: " + str(type(message)) + ", content: " + message)
parsed_message = json.loads(message)
print("Parsed message type: " + str(type(parsed_message)) + ", content: " + parsed_message)
And the output from this is:
Message type: <type 'unicode'>, content: "{\"action\":\"START_QUESTION_SELF\"}"
Parsed message type: <type 'unicode'>, content: {"action":"START_QUESTION_SELF"}
Now I would expect the second printed message to be a dict and I cannot figure out why this isn't working. Any help would be greatly appreciated.
json.loads()it's still seen as a unicode object and I cannot use it as a dict.Parsed message type: <type 'dict'>