OrderedDict, as discussed elsewhere, is the majority of the solutions to your problem, and "ObjDict" might be even better.
However, if you need an order saved during loading, you will also need json.loads () to load the values ββinto the OrderedDict. To do this, use
from collections import OrderedDict values=json.loads(jsontext,object_pairs_hook=OrderedDict)
Otherwise, even if the json file is in order, this order will be lost upon download.
Perhaps the best solution would be to use "ObjDict" instead of OrderedDict. This requires a pip installation object. ObjDict still maintains order, as in OrderedDict, but also supports JSON and improves the handling of this example.
from objdict import ObjDict values = ObjDict("""{"profile" : "testprofile", "format": "RSA_RC4_Sealed" }""") values.enc_key = base64.b64encode(chiave_da_inviare) values.request = base64.b64encode(data) values_json = values.dumps(separators=(',', ':'))
innov8 Feb 06 '16 at 5:02 2016-02-06 05:02
source share