1. 程式人生 > 其它 >python 讀取json格式資料保持原有順序

python 讀取json格式資料保持原有順序

技術標籤:Pythonpythonjson

import json
from collections import OrderedDict


with open("123.json", "r", encoding="utf-8") as f:
    jsonData = json.load(f,object_pairs_hook=OrderedDict)
    print(jsonData)
    jsonData["ID"] = "50"
with open("66.json", "w", encoding="utf-8") as f:
    json.dump(jsonData, f)