【发布时间】:2015-06-25 18:33:22
【问题描述】:
我有一个(无效的)json 文件,它是 UTF-8 格式
json的粗略是:
{u'key': {u'key2': u'value'}, ...., u'key3' : u'value'}
执行简单的 python json.loads() 会导致以下错误:
ValueError: Expecting property name: line 1 column 2 (char 1)
根据 SO 上的一些相关答案,我尝试将其更改为 unicode:
line = unicode(line,'utf-8')
data = json.loads(line)
ValueError: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)
我能想到的一个解决方案是用双引号替换所有单引号并继续,但我在想 - 如果有更简单的解决方案来解析文件以获取 python dict?
【问题讨论】:
-
我建议您通过 JSON Validator 运行您的 JSON 数据,您也可以通过 Google 搜索其他类型的数据。
-
检查源字符串中是否存在 \r\n 以及@joe-cheng refer