如何从Django JsonField获取数据?

时间:2022-12-05 19:21:27

I would like to know how I can get ("decode?") the data from a JsonField, I'm having this:

我想知道如何从JsonField获取(“解码?”)数据,我有这个:

{"pleople": "name=Jhon&email=email@domain.com", "id": 251304}

How I can pass this to my view like name['Jhon'] or any kind of object to use with querySet or parameter?

我如何将其传递给我的视图,如名称['Jhon']或任何与querySet或参数一起使用的对象?

1 个解决方案

#1


1  

>>> from urlparse import parse_qs, parse_qsl

>>> parse_qs("name=Jhon&email=email@domain.com")
{'email': ['email@domain.com'], 'name': ['Jhon']} # allow multiple values

>>> dict(parse_qsl("name=Jhon&email=email@domain.com"))
{'email': 'email@domain.com', 'name': 'Jhon'} # dict w/ single value

Or you could use django.http.QueryDict directly

或者你可以直接使用django.http.QueryDict

>>> from django.http import QueryQict
>>> QueryDict("name=Jhon&email=email@domain.com")
<QueryDict: {u'name': [u'Jhon'], u'email': [u'email@domain.com']}>

#1


1  

>>> from urlparse import parse_qs, parse_qsl

>>> parse_qs("name=Jhon&email=email@domain.com")
{'email': ['email@domain.com'], 'name': ['Jhon']} # allow multiple values

>>> dict(parse_qsl("name=Jhon&email=email@domain.com"))
{'email': 'email@domain.com', 'name': 'Jhon'} # dict w/ single value

Or you could use django.http.QueryDict directly

或者你可以直接使用django.http.QueryDict

>>> from django.http import QueryQict
>>> QueryDict("name=Jhon&email=email@domain.com")
<QueryDict: {u'name': [u'Jhon'], u'email': [u'email@domain.com']}>