import json

class Subscriber(object):
firstname
= None
lastname
= None


class Post(object):
author
= None
title
= None


def decode_from_dict(cls,vals):
obj
= cls()
for key, val in vals.items():
setattr
(obj, key, val)
return obj


SERIALIZABLE_CLASSES
= {'Subscriber': Subscriber,
'Post': Post}

def decode_object(d):
for field in d:
if field in SERIALIZABLE_CLASSES:
cls
= SERIALIZABLE_CLASSES[field]
return decode_from_dict(cls, d[field])
return d


results
= '''[{"Subscriber": {"firstname": "Neal", "lastname": "Walters"}},
{"Post": {"author": {"Subscriber": {"firstname": "Neal",
"lastname": "Walters"}}},
"title": "Decoding JSON Objects"}]'''

Comments

Popular posts from this blog

How to use the Inbox Repair Tool to recover messages in Outlook 2000 that is installed with Internet Mail Only option

ReadyNAS default login and password

Repair corrupt Outlook PST files with two Microsoft utilities