I guess my big question would be this: Why not use simplejson, which
includes encode/decode functions as part of the module?

On Thu, Apr 7, 2011 at 2:16 PM, [email protected] <
[email protected]> wrote:

> Before I go re-invent the wheel is there a framework or module for de-
> serialization JSON back into python objects?
>
> I've been doing something like this and a played around with setattr()
>
>
>    def decode_from_dict(self, cls, vals):
>        #obj = cls()
>        obj = cls
>        for key, val in vals.items():
>            print obj, key, val
>            setattr(obj, key, val)
>        return obj
>
>    def decode_object(self,d):
>        blah = CurriculumOrderItemModel()
>        return self.decode_from_dict(blah, d)
>
>    @expose()
>    def order_up(self):
>        order = '[{"orderID": 123334456, "moduleTitle": "Public/
> Financial D&O Liability Insurance"}]'
>        result = json.loads(order, object_hook=self.decode_object)
>
> --
> You received this message because you are subscribed to the Google Groups
> "TurboGears" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/turbogears?hl=en.
>
>


-- 
Michael J. Pedersen
My IM IDs: Jabber/[email protected], ICQ/103345809, AIM/pedermj022171
          Yahoo/pedermj2002, MSN/[email protected]
----------
  All humans fail, in both great and small ways we fail continually.
Machines fail too. Computers are machines that are managed by humans, the
fallout from failure can be spectacular. Your responsibility is to deal with
failure, to anticipate it and to eliminate it as far as is humanly and
economically wise to achieve. Are your actions part of the problem or part
of the solution?

-- 
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en.

Reply via email to