解码邮件时,我不断收到JSONDecodeError("Expecting value", s, err.value) from None
。该消息是由三个numpy数组组成的json。这是我的解码方式:
def decode_msg(data):
print(data)
data = json.loads(data)
img_code = np.asarray(data.get("code"))
img_user = np.asarray(data.get("user"))
img_msg = np.asarray(data.get("msg"))
steg_code = LSBSteg(img_code)
steg_user = LSBSteg(img_user)
steg_msg = LSBSteg(img_msg)
code = steg_code.decode_text()
user = steg_user.decode_text()
msg = steg_msg.decode_text()
return int(code), user, msg
这是我的编码方式:
def encode_msg(code, user, msg):
img_code = np.random.randint(0, 255, size=(14, 14, 3))
img_user = np.random.randint(0, 255, size=(34, 44, 3))
img_msg = np.random.randint(0, 255, size=(574, 664, 3))
steg_code = LSBSteg(img_code)
steg_user = LSBSteg(img_user)
steg_msg = LSBSteg(img_msg)
img_code_encoded = steg_code.encode_text((str(code)))
img_user_encoded = steg_user.encode_text((user))
img_msg_encoded = steg_msg.encode_text((msg))
data = json.dumps({"code": img_code_encoded.tolist(),
"user": img_user_encoded.tolist(),
"msg": img_msg_encoded.tolist()})
data = data.encode('utf-8')
print(data)
return data
当我在解码时打印“数据”时,我发现它被截断了。例如,如果这是经过编码的数据:{"msg": [[252, 170, 84], [16, 213, 200]]}
,则这是我在解码{"msg": [[252, 170, 84], [16, 213, 2
时打印时得到的,因此消息被截断了。当然,消息远不止于此。