'str' object has no attribute '__dict__'
Question: I want to serialize a dictionary to JSON in Python. I have this 'str' object
has no attribute '**dict** ' error. Here is my code...

    
    
    from django.utils import simplejson
    
    class Person(object):
        a = ""
    
    person1 = Person()
    person1.a = "111"
    
    person2 = Person()
    person2.a = "222"
    
    list = {}
    list["first"] = person1
    list["second"] = person2
    
    s = simplejson.dumps([p.__dict__ for p in list])
    

And the exception is;

    
    
    Traceback (most recent call last):
      File "/base/data/home/apps/py-ide-online/2.352580383594527534/shell.py", line 380, in post
        exec(compiled_code, globals())
      File "<string>", line 17, in <module>
    AttributeError: 'str' object has no attribute '__dict__'
    


Answer: How about

    
    
    s = simplejson.dumps([p.__dict__ for p in list.itervalues()])
    

