旧的出错信息包含在双引号期待物业名称: 我得到这个错误:ValueError异常:在Python
ValueError: Expecting property name enclosed in double quotes:
这是我的代码。我想字符串转换ResultPart在字典:
resultPart = '{"sentences": [{"parsetree": [], [("words": "Q", {"Lemma": "q", "NamedEntityTag": "O", "CharacterOffsetEnd": "1", "PartOfSpeech": "NN", "CharacterOffsetBegin": "0"})], "dependencies": [], "text": "Q", "parsetree": [], "indexeddependencies": []}]}'
resultPart2 = json.dumps(resultPart)
#result should be a dict
result = json.loads(resultPart)
编辑:我纠正了一部分,现在我已经此错误:
TypeError: string indices must be integers
这是新代码:
resultPart = "{'sentences': [{'words': [('Q', {'Lemma': 'q', 'NamedEntityTag': 'O', 'CharacterOffsetEnd': '1', 'PartOfSpeech': 'NN', 'CharacterOffsetBegin': '0'})], 'dependencies': [], 'text': 'Q', 'parsetree': [], 'indexeddependencies': []}]}"
resultPart2 = json.dumps(resultPart)
result = json.loads(resultPart2)
你似乎有一个'('在那里我期望一个''{ 。你为什么手工创建JSON? – jonrsharpe