我有以下json字符串
{
"meta": {
"limit": 20,
"next": null,
"offset": 0,
"previous": null,
"total_count": 3
},
"objects": [
{
"id": 1,
"name": "Exercicios_EO_JorgeLoureiro-cópia-não.está.exactament.igual.pdf\n",
"resource_uri": "/api/open/1/"
},
{
"id": 2,
"name": "api.py\n",
"resource_uri": "/api/open/2/"
},
{
"id": 3,
"name": "models.py\n",
"resource_uri": "/api/open/3/"
}
]
}
我从做服务器调用和阅读响应
response = url2.urlopen("http://127.0.0.1:8000/api/open/?format=json")
data = response.read()
然而,当我通过
将它从json加载到python时res = json.loads(data)
我从打印res获得:
{u'meta': {u'previous': None, u'total_count': 3, u'offset': 0, u'limit': 20, u'next': None}, u'objects': [{u'resource_uri': u'/api/open/1/', u'id': 1, u'name': u'Exercicios_EO_JorgeLoureiro-c\xf3pia-n\xe3o.est\xe1.exactament.igual.pdf\n'}, {u'resource_uri': u'/api/open/2/', u'id': 2, u'name': u'api.py\n'}, {u'resource_uri': u'/api/open/3/', u'id': 3, u'name': u'models.py\n'}]}
{"meta": {"limit": 20, "next": null, "offset": 0, "previous": null, "total_count": 3}, "objects": [{"id": 1, "name": "Exercicios_EO_JorgeLoureiro-cópia-não.está.exactament.igual.pdf\n", "resource_uri": "/api/open/1/"}, {"id": 2, "name": "api.py\n", "resource_uri": "/api/open/2/"}, {"id": 3, "name": "models.py\n", "resource_uri": "/api/open/3/"}]}
{u'meta': {u'previous': None, u'total_count': 3, u'offset': 0, u'limit': 20, u'next': None}, u'objects': [{u'resource_uri': u'/api/open/1/', u'id': 1, u'name': u'Exercicios_EO_JorgeLoureiro-c\xf3pia-n\xe3o.est\xe1.exactament.igual.pdf\n'}, {u'resource_uri': u'/api/open/2/', u'id': 2, u'name': u'api.py\n'}, {u'resource_uri': u'/api/open/3/', u'id': 3, u'name': u'models.py\n'}]}
{"meta": {"limit": 20, "next": null, "offset": 0, "previous": null, "total_count": 3}, "objects": [{"id": 1, "name": "Exercicios_EO_JorgeLoureiro-cópia-não.está.exactament.igual.pdf\n", "resource_uri": "/api/open/1/"}, {"id": 2, "name": "api.py\n", "resource_uri": "/api/open/2/"}, {"id": 3, "name": "models.py\n", "resource_uri": "/api/open/3/"}]}
{u'meta': {u'previous': None, u'total_count': 3, u'offset': 0, u'limit': 20, u'next': None}, u'objects': [{u'resource_uri': u'/api/open/1/', u'id': 1, u'name': u'Exercicios_EO_JorgeLoureiro-c\xf3pia-n\xe3o.est\xe1.exactament.igual.pdf\n'}, {u'resource_uri': u'/api/open/2/', u'id': 2, u'name': u'api.py\n'}, {u'resource_uri': u'/api/open/3/', u'id': 3, u'name': u'models.py\n'}]}
这就像我真正想要的3个副本,这就是json字符串到python。
有关可能发生的事情的任何线索?
提前致谢
这是完整的代码
response = url2.urlopen("http://127.0.0.1:8000/api/open/?format=json")
data = response.read()
print data
print "\n"
res = json.loads(data)
print res