[英]Python - SimpleJSON Issue
我正在使用Mega API和Python,希望产生一个Python可读的文件夹树。 目前,我正在使用Mega的API提供的JSON响应,但由于某种原因,在解析它时遇到了麻烦。 过去,我只是以下面的格式使用simplejson,尽管现在它不起作用。 目前,我只是想获取文件名。 任何帮助表示赞赏!
import simplejson
megaResponseToFileSearch = "(u'BMExefXbYa', {u'a': {u'n': u'A Bullet For Pretty Boy - 1 - Dial M For Murder.mp3'}, u'h': u'BMExXbYa', u'k': (5710166, 21957970, 11015946, 7749654L), u'ts': 13736999, 'iv': (7949460, 15946811, 0, 0), u'p': u'4FlnwBTb', u's': 5236864, 'meta_mac': (529642, 2979591L), u'u': u'xpz_tb-YDUg', u't': 0, 'key': (223xx15874, 642xx8505, 1571620, 26489769L, 799460, 1596811, 559642, 279591L)})"
jsonRespone = simplejson.loads(megaResponseToFileSearch)
print jsonRespone[u'a'][u'n']
错误:
Traceback (most recent call last):
File "D:/Projects/Mega Sync/megasync.py", line 18, in <module>
jsonRespone = simplejson.loads(file4)
File "D:\Projects\Mega Sync\simplejson\__init__.py", line 453, in loads
return _default_decoder.decode(s)
File "D:\Projects\Mega Sync\simplejson\decoder.py", line 429, in decode
obj, end = self.raw_decode(s)
File "D:\Projects\Mega Sync\simplejson\decoder.py", line 451, in raw_decode
raise JSONDecodeError("No JSON object could be decoded", s, idx)
simplejson.decoder.JSONDecodeError: No JSON object could be decoded: line 1 column 0 (char 0)
编辑:
我被问到从哪里得到琴弦的。 这是对使用Mega API搜索文件的响应。 我正在使用这里找到的模块。 https://github.com/richardasaurus/mega.py代码本身看起来像这样:
from mega import Mega
mega = Mega({'verbose': True})
m = mega.login(email, password)
file = m.find('A Bullet For Pretty Boy - 1 - Dial M For Murder.mp3')
print file
从m.find
中获得的东西只是一个python元组,其中第1个元素(在第0个元素之后)是一个字典:
(u'99M1Tazb',
{u'a': {u'n': u'test.txt'},
u'h': u'99M1Tazb',
u'k': (1145485578, 1435138417, 702505527, 274874292),
u'ts': 1373482712,
'iv': (1883603069, 763415510, 0, 0),
u'p': u'9td12YaY',
u's': 0,
'meta_mac': (1091379956, 402442960),
u'u': u'79_166PAQCA',
u't': 0,
'key': (872626551, 2013967015, 1758609603, 127858020, 1883603069, 763415510, 1091379956, 402442960)})
要获取文件名,只需使用:
print file[1]['a']['n']
因此,根本不需要使用simplejson
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.