I have the following string
{\"action\":\"print\",\"method\":\"onData\",\"data\":\"Madan Mohan\"}
I Want to deserialize to a object of cla
Another way is to simply pass the json string as a dict to the constructor of your object. For example your object is:
class Payload(object):
def __init__(self, action, method, data, *args, **kwargs):
self.action = action
self.method = method
self.data = data
And the following two lines of python code will construct it:
j = json.loads(yourJsonString)
payload = Payload(**j)
Basically, we first create a generic json object from the json string. Then, we pass the generic json object as a dict to the constructor of the Payload class. The constructor of Payload class interprets the dict as keyword arguments and sets all the appropriate fields.