I am running Python 2.7 (x64 Linux) and trying to convert a dict
to a JSON object.
>>> import sys
>>> sys.version_info
sys.version_info(major=2, minor=7, micro=0, releaselevel='final', serial=0)
I am trying to use simplejson
(falling back to json
from the standard library) but I get the following error:
>>> try: import simplejson as json
... except ImportError: import json
...
>>> metadata = dict()
>>> metadata['foo'] = 'bar'
>>> print metadata
{'foo': 'bar'}
>>> json.dumps(metadata)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'dumps'
Is there something obvious I am missing about using json
or simplejson
with Python 2.7?
question from:
https://stackoverflow.com/questions/11369734/python-json-module-has-no-attribute-dumps 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…