[b"['2018-10-11 08:16:00', 6498, 6525, 6497.5, 6503.5, 1539216960000]", b"['2018-10-11 08:17:00', 6503.5, 6523.5, 6497.5, 6514.5, 1539217020000]", b"['2018-10-11 08:18:00', 6514.5, 6515, 6490.5, 6492, 1539217080000]", b"['2018-10-11 08:19:00', 6492, 6495, 6490, 6490, 1539217140000]",]
我从 redis 取出的数据是这样 要怎么将他转换为嵌套列表呢,这个 b 要怎么去掉呢
1
enenaaa 2018-10-11 14:45:37 +08:00
b 说明是二进制串。 转成 unicode 后, 按 json 解析。
|
2
locoz 2018-10-11 14:49:11 +08:00
[json.loads(i.decode().replace("'", '"')) for i in a]
|
3
ltoddy 2018-10-11 20:40:18 +08:00
```
>>> d = [b"['2018-10-11 08:16:00', 6498, 6525, 6497.5, 6503.5, 1539216960000]", b"['2018-10-11 08:17:00', 6503.5, 6523.5, 6497.5, 6514.5, 1539217020000]", b"['2018-10-11 08:18:00', 6514.5, 6515, 6490.5, 6492, 1539217080000]", b"['2018-10-11 08:19:00', 6492, 6495, 6490, 6490, 1539217140000]",] >>> >>> >>> >>> [s.decode() for s in d] ["['2018-10-11 08:16:00', 6498, 6525, 6497.5, 6503.5, 1539216960000]", "['2018-10-11 08:17:00', 6503.5, 6523.5, 6497.5, 6514.5, 1539217020000]", "['2018-10-11 08:18:00', 6514.5, 6515, 6490.5, 6492, 1539217080000]", "['2018-10-11 08:19:00', 6492, 6495, 6490, 6490, 1539217140000]"] >>> ``` |
4
datou 2018-10-13 00:07:43 +08:00
redis 读数据库的时候有个参数是编码成字符串
|