我想使用Python将JSON数据转换为Python对象.
我从Facebook API接收JSON数据对象,我想将其存储在我的数据库中.
我目前在Django中查看(Python)(request.POST包含JSON):
response = request.POST
user = FbApiUser(user_id = response['id'])
user.name = response['name']
user.username = response['username']
user.save()
Run Code Online (Sandbox Code Playgroud)
这工作正常,但我如何处理复杂的JSON数据对象?
如果我能以某种方式将这个JSON对象转换为Python对象以便于使用,那会不会更好?
如何设置/获取t给定的属性值x.
class Test:
def __init__(self):
self.attr1 = 1
self.attr2 = 2
t = Test()
x = "attr1"
Run Code Online (Sandbox Code Playgroud) 我怎样才能完成这样的工作:
def get_foo(someobject, foostring):
return someobject.foostring
Run Code Online (Sandbox Code Playgroud)
IE:
如果我这样做get_foo(obj, "name")应该是调用obj.name(请参阅输入字符串,但我称之为attritube.
谢谢