大致流程:
代碼:
import collections real_result = collections.OrderedDict() real_result["target"] = "total_result" real_result["key1"] = "value1" real_result["key2"] = "value2" real_result["key3"] = "value3" real_result_total = [real_result] print real_result_total 輸出:[OrderedDict([('target', 'total_result'), ('key1', 'value1'), ('key2', 'value2'), ('key3', 'value3')])] current_dir = os.path.dirname(os.path.realpath(__file__)) path = os.path.join(os.path.join(current_dir, 'jsonfile'), result_json) with open(path, 'w') as f: json.dump(real_result_total, f, encoding="utf-8", ensure_ascii=False, indent=4, separators=(',', ':'))
json文件:
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持億速云。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。