028-86922220

建站动态

根据您的个性需求进行定制 先人一步 抢占小程序红利时代

python字典有序并写入json文件过程解析-创新互联

大致流程:

创新互联建站技术团队十载来致力于为客户提供网站建设、成都网站制作、高端网站设计成都营销网站建设、搜索引擎SEO优化等服务。经过多年发展,公司拥有经验丰富的技术团队,先后服务、推广了上千家网站,包括各类中小企业、企事单位、高校等机构单位。

代码:

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=(',', ':'))

当前题目:python字典有序并写入json文件过程解析-创新互联
本文链接:http://www.tsicrk.com/article/gdcge.html

其他资讯

让你的专属顾问为你服务

2.2670s