简体   繁体   English

json.decoder.JSONDecodeError:期望','分隔符:python中的错误

[英]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.

相关问题 Python Json.decoder.JSONDecodeError:期望','分隔符: - Python Json.decoder.JSONDecodeError: Expecting ',' delimiter: json.decoder.JSONDecodeError: 期待 ',' 分隔符: - json.decoder.JSONDecodeError: Expecting ',' delimiter: 使用Python读取大JSON文件时出错:“ json.decoder.JSONDecodeError:预期为','分隔符” - Error while reading a big JSON file with Python: “json.decoder.JSONDecodeError: Expecting ',' delimiter” 有效 json 给出 json.decoder.JSONDecodeError: Expecting ',' delimiter - Valid json giving json.decoder.JSONDecodeError: Expecting ',' delimiter json.decoder.JSONDecodeError:期望值:第 1 行第 1 列(字符 0)python - json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0) python Python:json.decoder.JSONDecodeError:期望值:第 1 行第 1 列(字符 0) - Python: json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0) json.decoder.JSONDecodeError:期望值:第2行第1列(char 1)错误 - json.decoder.JSONDecodeError: Expecting value: line 2 column 1 (char 1) error 错误:json.decoder.JSONDecodeError:期望值:第 1 行第 1 列(字符 0) - ERROR: json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0) Python JSON解析器错误:json.decoder.JSONDecodeError:预期值:第1行第1列(字符0) - Python JSON parser error: json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0) 为什么python JSON模块显示错误:json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0) - Why does the python JSON module show the error : json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM