[Python] JSON Serialize a Python Class

Marco Olimpi badstorm a gmail.com
Sab 11 Gen 2014 18:46:45 CET


Hi,
i'm traing to serialize my called in python. This is my example:
I have this two classes:

*class User():*
*  def __init__(self, _name, _lastname):*
*       self.Name = _name*
*       self.LastName = _lastname*

*class News():*
*  def __init__(self, _news,_user):*
*       self.News = _news*
*       self.User = _user*


than i create my class in my code:

...
*myUser = User("Mario","Rossi")*
*myNews = News("My last news", myUser)*

*JSONstring = dumps(myNews)*
...

but in the last line of code i get the error that the News class is not
JSON serializable.

How I can make this work?

Thanks.

Regards

Marco
-------------- parte successiva --------------
Un allegato HTML è stato rimosso...
URL: <http://lists.python.it/pipermail/python/attachments/20140111/d2d431e1/attachment.html>


Maggiori informazioni sulla lista Python