我想解析一个 JSON 格式的 bytes
字符串,将其转换为 python 对象。这是我所掌握的资料来源:
my_bytes_value = b'[{\'Date\': \'2016-05-21T21:35:40Z\', \'CreationDate\': \'2012-05-05\', \'LogoType\': \'png\', \'Ref\': 164611595, \'Classe\': [\'Email addresses\', \'Passwords\'],\'Link\':\'http://some_link.com\'}]'
这就是我想要的结果:
[{
"Date": "2016-05-21T21:35:40Z",
"CreationDate": "2012-05-05",
"LogoType": "png",
"Ref": 164611595,
"Classes": [
"Email addresses",
"Passwords"
],
"Link": "http://some_link.com"}]
首先,我将字节转换为字符串:
my_new_string_value = my_bytes_value.decode("utf-8")
但是当我尝试调用 loads
将其解析为 JSON 时:
my_json = json.loads(my_new_string_value)
我得到了这个错误:
json.decoder.JSONDecodeError: Expecting value: line 1 column 174 (char 173)