import simplejson
from urllib2 import urlopen
from simplejson import loads
from django.core import serializers
content = loads(urlopen('https://graph.facebook.com/1234676502/feed').read())
content = simplejson.dumps(content,sort_keys=True, indent=4)
print content
json_serializer = serializers.get_serializer("json")()
json_serializer.deserialize(content)
次のエラーを取得して上記のpythonコードイムを実行している間:このJSONオブジェクトを逆シリアル化するにはどうすればよいですか?
Traceback (most recent call last):
File "/var/www/youedo/test.py", line 22, in <module>
json_serializer = serializers.get_serializer("json")()
File "/usr/local/lib/python2.6/dist-packages/django/core/serializers/__init__.py", line 63, in get_serializer
_load_serializers()
File "/usr/local/lib/python2.6/dist-packages/django/core/serializers/__init__.py", line 109, in _load_serializers
register_serializer(format, BUILTIN_SERIALIZERS[format], serializers)
File "/usr/local/lib/python2.6/dist-packages/django/core/serializers/__init__.py", line 51, in register_serializer
module = importlib.import_module(serializer_module)
File "/usr/local/lib/python2.6/dist-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/usr/local/lib/python2.6/dist-packages/django/core/serializers/xml_serializer.py", line 6, in <module>
from django.core.serializers import base
File "/usr/local/lib/python2.6/dist-packages/django/core/serializers/base.py", line 7, in <module>
from django.db import models
File "/usr/local/lib/python2.6/dist-packages/django/db/__init__.py", line 14, in <module>
if not settings.DATABASES:
File "/usr/local/lib/python2.6/dist-packages/django/utils/functional.py", line 276, in __getattr__
self._setup()
File "/usr/local/lib/python2.6/dist-packages/django/conf/__init__.py", line 38, in _setup
raise ImportError("Settings cannot be imported, because environment variable %s is undefined." % ENVIRONMENT_VARIABLE)
ImportError: Settings cannot be imported, because environment variable DJANGO_SETTINGS_MODULE is undefined.
...と私はそれが正しくJSON文字列を出力したコンテンツを印刷します。
編集:2 含量=負荷(urlopen( 'https://graph.facebook.com/1234676502/feed django.coreインポートシリアライザからのsimplejsonインポート負荷 からurlopen urllib2のインポートから のsimplejsonインポート「).read())
json_serializer = serializers.get_serializer("json")()
json_serializer.get_deserialize(content)
私はview.pyにこのコードを置くが、その後、私は次のエラーを得た:
AttributeError at /rss
'Serializer' object has no attribute 'get_deserialize'
Request Method: GET
Request URL: http://127.0.0.1:8000/rss
Django Version: 1.2.4
Exception Type: AttributeError
Exception Value:
'Serializer' object has no attribute 'get_deserialize'
私はこのエラーが発生しました "タイプオブジェクト 'シリアライザ'の属性は 'deserialize'です" – Prem