有没有简单的方法在 Django 中编码 json 数据?
我将从 OpenID 提供商处获取如下数据:
{"identity":"http:\/\/admin.lol.com\/","provider":"http:\/\/lol.com\/server\/",
"name":{"full_name":"\u0421\u0435\u0440\u0433\u0435\u0439 \u0421\u0435\u0440\u0433\u0435\u0439"},
"nickname":"admin","email":"[email protected]","gender":"M","dob":"1985-01-31"}
如何获取此数据?
I will get data like this from OpenID provider:
{"identity":"http:\/\/admin.lol.com\/","provider":"http:\/\/lol.com\/server\/",
"name":{"full_name":"\u0421\u0435\u0440\u0433\u0435\u0439 \u0421\u0435\u0440\u0433\u0435\u0439"},
"nickname":"admin","email":"[email protected]","gender":"M","dob":"1985-01-31"}
How to get this data?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
默认情况下,Django 将 simplejson 库捆绑在 django.utils.simplejson (http://undefined.org/python/#simplejson )。此外,如果您使用的是 python 2.6 或更高版本,您只需
import json
即可获得内置 json 库一旦您决定使用一个库,您只需将 json 字符串传递给该库的解码器即可。对于内置 json 库,将是:
Django by default bundles the simplejson library at django.utils.simplejson (http://undefined.org/python/#simplejson). Additionally if you're using python 2.6 or better you can simply
import json
and you will get the builtin json libraryhttp://docs.python.org/library/json.html. There are also a multitude of other python json libraries, but those two should be vastly more than adequate.Once you have decided on a library to use you will simply need to pass your json string to the decoder of that library. For the builtin json library that would be:
http://docs.python.org/library/json.html
http://docs.python.org/library/json.html