我在 python 中有一个服务器,它以以下格式接收数据:
MultiDict([('JSONdata', u'{"SMS":[{"inbox":[{"body":"BACKUP *qqqqq*","phone":"+920000000"},{"body":"BACKUP *qqqqq*","phone":"+920000000"},{"body":"BACKUP *qqqqq*","phone":"+920000000"},{"body":"BACKUP *qqqqq*","phone":"+920000000"},{"body":"BACKUP *qqqqq*","phone":"+920000000"},{"body":"BACKUP *qqqqq*","phone":"+920000000"},{"body":"BACKUP *qqqqq*","phone":"+920000000"},{"body":"BACKUP *qqqqq*","phone":"+920000000":"BACKUP *qqqqq*","phone":"+920000000"},{"body":"BACKUP \\"qqqqq\\" ","phone":"+920000000"},{"body":"BACKUP \\"qqqqq\\" ","phone":"+920000000"},{"body":"BACKUP \\"qqqqq\\" ","phone":"+920000000"},]},{"sent":[]}]}')])
我编写了以下代码来获取它并将其转换为 JSONObject:
request.POST.getall('JSONdata')
incomingData = json.load(str)
但我收到错误:
Traceback (most recent call last):
File "/usr/lib/python2.7/wsgiref/handlers.py", line 85, in run
self.result = application(self.environ, self.start_response)
File "/home/anam/pyckenv/local/lib/python2.7/site-packages/pyramid/router.py", line 251, in __call__
response = self.invoke_subrequest(request, use_tweens=True)
File "/home/anam/pyckenv/local/lib/python2.7/site-packages/pyramid/router.py", line 227, in invoke_subrequest
response = handle_request(request)
File "/home/anam/cdsr/myproject/auth.py", line 50, in auth_request
return handler(request)
File "/home/anam/pyckenv/local/lib/python2.7/site-packages/pyramid_debugtoolbar/toolbar.py", line 130, in toolbar_tween
return handler(request)
File "/home/anam/pyckenv/local/lib/python2.7/site-packages/pyramid/tweens.py", line 21, in excview_tween
response = handler(request)
File "/home/anam/pyckenv/local/lib/python2.7/site-packages/pyramid_tm/__init__.py", line 82, in tm_tween
reraise(*exc_info)
File "/home/anam/pyckenv/local/lib/python2.7/site-packages/pyramid_tm/__init__.py", line 63, in tm_tween
response = handler(request)
File "/home/anam/pyckenv/local/lib/python2.7/site-packages/pyramid/router.py", line 161, in handle_request
response = view_callable(context, request)
File "/home/anam/pyckenv/local/lib/python2.7/site-packages/pyramid/config/views.py", line 347, in rendered_view
result = view(context, request)
File "/home/anam/pyckenv/local/lib/python2.7/site-packages/pyramid/config/views.py", line 493, in _requestonly_view
response = view(request)
File "/home/anam/cdsr/myproject/controllers/controllers.py", line 44, in data
incomingData = json.load(str)
File "/usr/lib/python2.7/json/__init__.py", line 274, in load
return loads(fp.read(),
AttributeError: 'list' object has no attribute 'read'
QMobile-A8 - - [11/Oct/2013 08:24:08] "POST /data HTTP/1.1" 500 59
我尝试了不同的方法来解决它,但没有任何效果.. ??? 有人可以告诉我我做错了什么吗?