Can I get JSON to load into an OrderedDict?

前端 未结 6 949
别跟我提以往
别跟我提以往 2020-11-22 01:13

Ok so I can use an OrderedDict in json.dump. That is, an OrderedDict can be used as an input to JSON.

But can it be used as an output? If so how? In my

6条回答
  •  走了就别回头了
    2020-11-22 01:50

    Simple version for Python 2.7+

    my_ordered_dict = json.loads(json_str, object_pairs_hook=collections.OrderedDict)
    

    Or for Python 2.4 to 2.6

    import simplejson as json
    import ordereddict
    
    my_ordered_dict = json.loads(json_str, object_pairs_hook=ordereddict.OrderedDict)
    

提交回复
热议问题