[英]json.decoder.JSONDecodeError: Expecting ',' delimiter: Error in python
I send json data with socket in python我用python中的套接字发送json数据
{"receiver": "2", "sender:": 1, "seq_num": 10, "data": "{"iv": "jdjhvwGriJ95kZwgDWlShw==", "ciphertext": "Fg7ugYYAnPzL+lG8d7QDDA=="}"} {"receiver": "2", "sender:": 1, "seq_num": 10, "data": "{"iv": "jdjhvwGriJ95kZwgDWlShw==", "ciphertext": "Fg7ugYYAnPzL+lG8d7QDDA=="} "}
Here is the data that I send.这是我发送的数据。 And it is string type, because I couldn't use sendall for json type.
它是字符串类型,因为我不能将 sendall 用于 json 类型。
And when I receive it, I tried to make that string into json.当我收到它时,我试图将该字符串转换为 json。 So I did,
所以我做了,
data = client_socket.recv(1024)
#data = json.loads(data)
data = json.loads(json.dumps(data))
I got json.decoder.JSONDecodeError: Expecting ',' delimiter: line 1 column 59 (char 58) error.我得到 json.decoder.JSONDecodeError: Expecting ',' delimiter: line 1 column 59 (char 58) 错误。
Please help!请帮忙!
There's a syntax error in your data
field.您的
data
字段中存在语法错误。 By putting it in as "{"iv": "jdjhvwGriJ95kZwgDWlShw==", "ciphertext": "Fg7ugYYAnPzL+lG8d7QDDA=="}"
, the double quotes mess up the encoder, causing it to throw an error.通过将其放入
"{"iv": "jdjhvwGriJ95kZwgDWlShw==", "ciphertext": "Fg7ugYYAnPzL+lG8d7QDDA=="}"
,双引号会弄乱编码器,导致它抛出错误。
If you wanted to value to be an object, you can simply remove the enclosing quotes like so:如果您想将 value 作为一个对象,您可以简单地删除封闭的引号,如下所示:
data = {"receiver": "2", "sender:": 1, "seq_num": 10, "data": {"iv": "jdjhvwGriJ95kZwgDWlShw==", "ciphertext": "Fg7ugYYAnPzL+lG8d7QDDA=="}}
However, if you want it to be a string, then you have to make all of the double quotes inside escaped like this :但是,如果你希望它是一个字符串,那么你必须像这样转义里面的所有双引号:
{
"receiver": "2", "sender:": 1, "seq_num": 10,
"data": "{\"iv\": \"jdjhvwGriJ95kZwgDWlShw==\", \"ciphertext\": \"Fg7ugYYAnPzL+lG8d7QDDA==\"}"
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.