During network-based transmission, most numbers are converted to strings (except binary). JSON serialization is a common method because it is often required to convert strings into classes, how do I return the received JSON string to the class? Python has no reflection. We usually load the string into a JSON object first, so that it becomes a dict, and then parse:
Class struct: def _ init _ (self, ** entries): Self. _ dict __. update (entries) then, you can use: >>> ARGs = {'A': 1, 'B ': 2 }>>> S = struct (** ARGs) >>>s <__ main __. struct instance at 0x01d6a738 >>> S. a1 >>>> S. b2
Of course, it is unrealistic to change the constructor of each class one by one. This provides an idea. I will temporarily create a new class instance, then update its dictionary to get the object:
Import jsonclass student (object): name = "" age = nonertnvalue = remotemethod (Params **) # The formatted JSON string parsed = JSON is obtained here. loads (rtnvalue, "UTF-8") ST = student () ST. _ dict __. update (parsed)