舊的出錯信息包含在雙引號期待物業名稱: 我得到這個錯誤: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