Python JSON Google Translator解析为Simplejson问题
|
我正在尝试在Python中使用simplejson解析Google翻译结果。但是我收到以下异常。
Traceback (most recent call last):
File \"Translator.py\", line 45, in <module>
main()
File \"Translator.py\", line 41, in main
parse_json(trans_text)
File \"Translator.py\", line 29, in parse_json
json = simplejson.loads(str(trans_text))
File \"/usr/local/lib/python2.6/dist-packages/simplejson-2.1.3-py2.6-linux-i686.egg/simplejson/__init__.py\", line 385, in loads
return _default_decoder.decode(s)
File \"/usr/local/lib/python2.6/dist-packages/simplejson-2.1.3-py2.6-linux-i686.egg/simplejson/decoder.py\", line 402, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File \"/usr/local/lib/python2.6/dist-packages/simplejson-2.1.3-py2.6-linux-i686.egg/simplejson/decoder.py\", line 418, in raw_decode
obj, end = self.scan_once(s, idx)
simplejson.decoder.JSONDecodeError: Expecting property name: line 1 column 1 (char 1)
这是我的json对象看起来像
{\'translations\': [{\'translatedText\': \'fleur\'}, {\'translatedText\': \'voiture\'}]}
谁能告诉我这是什么问题?
没有找到相关结果
已邀请:
3 个回复
贡炮逗握惫
“ 3”不是字符串(str或unicode)或缓冲区对象。
错误消息和your5ѭ报告证明了这一点: 这是我的跨文本代表
是字典。 如果要将其转换为JSON字符串,则需要使用
,而不是
。 如果您想将结果用于其他用途,则只需将数据挖掘出来,例如
剿畦缄饥小
膝垫富顷
|
字符s13ѭ