使用 dumps函数时将属性 sort_keys设为 True 则按字典中的键来排序 a - z , 1-9
sk_True = json.dumps({"d": 5, "c": 8, "b": 7, "a": 9}, sort_keys=True).encode()
sk_False = json.dumps({"a": 5, "b": 8, "c": 7, "d": 9}).encode()
print(f‘sk_True: {sk_True}‘)
print(f‘sk_False: {sk_False}‘)
sk_int_True = json.dumps({2: ‘3‘, 4: ‘1‘, 1: ‘4‘, 3: ‘2‘}, sort_keys=True).encode()
sk_int_False = json.dumps({1: ‘4‘, 2: ‘3‘, 3:‘2‘, 4: ‘1‘}).encode()
print(f‘sk_int_True: {sk_int_True}‘)
print(f‘sk_int_False: {sk_int_False}‘)
sk_cint_True = json.dumps({2: 3, 4: 1, 1: 4, 3: 2}, sort_keys=True).encode()
sk_cint_False = json.dumps({1: 4, 2: 3, 3: 2, 4: 1}).encode()
print(f‘sk_int_True: {sk_cint_True}‘)
print(f‘sk_int_False: {sk_cint_False}‘)