【发布时间】:2020-01-03 13:34:36
【问题描述】:
Python Escape 双引号字符并将字符串转换为json
我试过用转义字符转义双引号,但也没有用
raw_string = '[{"Attribute":"color","Keywords":"green","AttributeComments":null},{"Attribute":" season","Keywords":["Holly Berry"],"AttributeComments":null},{"Attribute":" size","Keywords":"20"x30"","AttributeComments":null},{"Attribute":" unit","Keywords":"1","AttributeComments":null}]'
new_data = json.loads(raw_string)
它加载错误说期望','分隔符:第1行第180列(字符179)
预期的输出是JSON字符串
【问题讨论】:
-
这里的值不正确 --->
:"20"x30"",你需要解决这个问题 -
这里有格式错误:
"Keywords":"20"x30"",比如改成"Keywords":"20x30" -
@RomanPerekhrest 感谢您的回复,但这是我从数据库中获取的数据
-
你的python字符串
raw_string是一个有效的字符串,但不是有效的json。您需要先修复字符串。你是怎么拿到那根弦的?为什么你认为它可能是json?