Django simplejson 错误
我正在尝试使用 simplejson 来解析 JSON 字符串。由于某种原因,当我使用 simplejson.loads 时,我收到以下错误:
ERROR:root:Exception in request:
Traceback (most recent call last):
File "C:\django\lokus_web_new\django\core\handlers\base.py", line 111, in get_
response
response = callback(request, *callback_args, **callback_kwargs)
File "C:\django\lokus_web_new\mobile\views.py", line 13, in entry_ajax
test = simplejson.loads(entry_param)
File "C:\Program Files (x86)\Google\google_appengine\lib\simplejson\simplejson
\__init__.py", line 388, in loads
return _default_decoder.decode(s)
File "C:\Program Files (x86)\Google\google_appengine\lib\simplejson\simplejson
\decoder.py", line 402, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Program Files (x86)\Google\google_appengine\lib\simplejson\simplejson
\decoder.py", line 420, in raw_decode
raise JSONDecodeError("No JSON object could be decoded", s, idx)
JSONDecodeError: No JSON object could be decoded: line 1 column 0 (char 0)
INFO:root:"POST /entry_ajax/ HTTP/1.1" 500 -
JSON 字符串由本机 javscript JSON.stringify 函数生成,如下所示:
{'type':'basic','id':'156','payload':{'text':'asd'}}
以下是视图的代码:
def entry_ajax(request):
entry_param = str(request.POST)
test = simplejson.loads(entry_param)
return HttpResponse(test['type'])
有什么想法吗?
I'm attempting to use simplejson to parse a JSON string. For some reason, when I use simplejson.loads I recieve the following error:
ERROR:root:Exception in request:
Traceback (most recent call last):
File "C:\django\lokus_web_new\django\core\handlers\base.py", line 111, in get_
response
response = callback(request, *callback_args, **callback_kwargs)
File "C:\django\lokus_web_new\mobile\views.py", line 13, in entry_ajax
test = simplejson.loads(entry_param)
File "C:\Program Files (x86)\Google\google_appengine\lib\simplejson\simplejson
\__init__.py", line 388, in loads
return _default_decoder.decode(s)
File "C:\Program Files (x86)\Google\google_appengine\lib\simplejson\simplejson
\decoder.py", line 402, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Program Files (x86)\Google\google_appengine\lib\simplejson\simplejson
\decoder.py", line 420, in raw_decode
raise JSONDecodeError("No JSON object could be decoded", s, idx)
JSONDecodeError: No JSON object could be decoded: line 1 column 0 (char 0)
INFO:root:"POST /entry_ajax/ HTTP/1.1" 500 -
The JSON string is being generated by the native javscript JSON.stringify function and is as follows:
{'type':'basic','id':'156','payload':{'text':'asd'}}
The following is the code of the view:
def entry_ajax(request):
entry_param = str(request.POST)
test = simplejson.loads(entry_param)
return HttpResponse(test['type'])
Any thoughts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这不是有效的 JSON 字符串。使用双引号:
This is not a valid JSON string. Use double quotes: