读取如下数据想转换成字典json.loads()时报错,用ast模块即可解决。
如原始数据格式:{'tv': ['3DDDFC53136993750039653F73F3FC16.1501072660144', '6DA658E6A8B6412ACA4AB81CB48C7448.1506155551158', '3DDDFC53136993750039653F73F3FC16.1501072660144', 'FF0270B661D28F7C93EE67F13C23F45D.1516321289212', 'D0F4556010EAA10358CEB42513D940F4.1490681045222', '87F8FA280D24CD33A2EE3A087D8E917B.1514015381466', 'A79B3DDA22BD097B5D8AA736CF8FB0E3.1517372572622', 'E1DDE7D06CAE778FF15AA41DEE6B823E.1481353636179', '5D8B0FC5E930D15562580B32F25313A8.1515814943493', 'B817E3C56444CC3ABFB644593CF91061.1501226966314']}
报错:
ValueError: Expecting property name: line 1 column 2 (char 1)
正确的读取转换方法如下:
import ast
dict_x = ast.literal_eval(i_string)
即可
阅读(89851) | 评论(0) | 转发(0) |