editChaPingJsonFile.py

import jsondef get_json_data_desc(fileSrc,content):with open(fileSrc, 'rb') as f:  # 使用只读模型,并定义名称为fparams = json.load(f)  # 加载json文件中的内容给params# params["code"] = "505"params["imp"][0]["desc"] = content  # imp字段对应的desc的值修改为endprint("修改后的desc的值为:"+params["imp"][0]["desc"])  # 打印# f.close()  # 关闭json读模式,但是本身with函数会自动关闭文件,所以不需要手动关闭了return params  # 返回修改后的内容def get_json_data_title(fileSrc,content):with open(fileSrc, 'rb') as f:  # 使用只读模型,并定义名称为fparams = json.load(f)  # 加载json文件中的内容给params# params["code"] = "505"params["imp"][0]["title"] = content  # imp字段对应的deeplink的值修改为endprint("修改后的title值为:"+params["imp"][0]["title"])  # 打印# f.close()  # 关闭json读模式,但是本身with函数会自动关闭文件,所以不需要手动关闭了return params  # 返回修改后的内容# 写入json文件# 使用写模式,名称定义为r
def write_json_data(params,fileSrc):with open(fileSrc, 'w') as r:# 将params写入名称为r的文件中json.dump(params, r)# 关闭json写模式# r.close()

editChaPingFile.py

import json
import os
from editChapingFile.editChaPingJsonFile import get_json_data_desc, write_json_data, get_json_data_titlename_chaping = ["bidding.json", "友盟模板.json", "友盟自渲染.json", "百度新插屏.json", "百度自渲染旧版.json", "百度自渲染新版.json", "广点通模板.json", "广点通自渲染旧版.json", "广点通自渲染新版.json", "头条feed自渲染.json","头条模板.json", "头条新插屏.json", "头条自渲染旧版.json", "头条自渲染新版.json"]
src = "D:\\z\\mytest\\"
def editchapingFile():path = "D:\\z\\mytest"datanames = os.listdir(path)list = []for i in datanames:list.append(i)fileSrc = src+iprint("正在修改文件:"+fileSrc)if i == name_chaping[1]:content = "um"the_revised_dict = get_json_data_desc(fileSrc, content)write_json_data(the_revised_dict,fileSrc)elif i == name_chaping[2]:content = "um_custom_table_screen"the_revised_dict = get_json_data_desc(fileSrc, content)write_json_data(the_revised_dict,fileSrc)elif i == name_chaping[3]:content = "baidu_new"the_revised_dict = get_json_data_desc(fileSrc, content)write_json_data(the_revised_dict,fileSrc)elif i == name_chaping[4]:content = "baidu_custom_table_screen"the_revised_dict = get_json_data_desc(fileSrc, content)write_json_data(the_revised_dict,fileSrc)content = "toutiao"the_revised_dict = get_json_data_title(fileSrc, content)write_json_data(the_revised_dict, fileSrc)elif i == name_chaping[5]:content = "baidu_custom_table_screen"the_revised_dict = get_json_data_desc(fileSrc, content)write_json_data(the_revised_dict,fileSrc)content = "new_style"the_revised_dict = get_json_data_title(fileSrc, content)write_json_data(the_revised_dict, fileSrc)elif i == name_chaping[6]:content = "tencent"the_revised_dict = get_json_data_desc(fileSrc, content)write_json_data(the_revised_dict, fileSrc)elif i == name_chaping[7]:content = "tencent_custom_table_screen"the_revised_dict = get_json_data_desc(fileSrc, content)write_json_data(the_revised_dict, fileSrc)content = "toutiao"the_revised_dict = get_json_data_title(fileSrc, content)write_json_data(the_revised_dict, fileSrc)elif i == name_chaping[8]:content = "tencent_custom_table_screen"the_revised_dict = get_json_data_desc(fileSrc, content)write_json_data(the_revised_dict, fileSrc)content = "new_style"the_revised_dict = get_json_data_title(fileSrc, content)write_json_data(the_revised_dict, fileSrc)elif i == name_chaping[9]:content = "toutiao_custom_table_screen_feed"the_revised_dict = get_json_data_desc(fileSrc, content)write_json_data(the_revised_dict, fileSrc)elif i == name_chaping[10]:content = "toutiao"the_revised_dict = get_json_data_desc(fileSrc, content)write_json_data(the_revised_dict, fileSrc)elif i == name_chaping[11]:content = "toutiao_new"the_revised_dict = get_json_data_desc(fileSrc, content)write_json_data(the_revised_dict, fileSrc)elif i == name_chaping[12]:content = "toutiao_custom_table_screen"the_revised_dict = get_json_data_desc(fileSrc, content)write_json_data(the_revised_dict, fileSrc)content = "toutiao"the_revised_dict = get_json_data_title(fileSrc, content)write_json_data(the_revised_dict, fileSrc)elif i == name_chaping[13]:content = "toutiao_custom_table_screen"the_revised_dict = get_json_data_desc(fileSrc, content)write_json_data(the_revised_dict, fileSrc)content = "new_style"the_revised_dict = get_json_data_title(fileSrc, content)write_json_data(the_revised_dict, fileSrc)else:content = "bidding"print("bidding模式的link字段需要自己配置id哦!!!")the_revised_dict = get_json_data_desc(fileSrc, content)write_json_data(the_revised_dict, fileSrc)print(list)editchapingFile()

python批量修改json文件相关推荐

  1. 使用python批量修改txt文件中的信息

    使用python批量修改txt文件 在更改深度学习很多标签文件的时候,我们有时候需要自己修改txt文件里的路径,这时候如果写一个python程序,就会比较容易: import os import ra ...

  2. Python批量修改txt文件的某列数值

    Python批量修改txt文件的某列数值,在针对使用YOLOv5目标检测算法过程中,会面临更改标注文件(.txt文件)标签的情况,以将txt文件中第一列为0的数改为1为例,则可使用如下代码进行修改: ...

  3. 用Python批量修改hex文件的内容

    用Python批量修改hex文件的内容 文章目录 用Python批量修改hex文件的内容 0.前言 1.代码 0.前言 先保存下来,电脑要清空了..... 后续补上:大概关于hex校验码,从大的hex ...

  4. 使用Python批量修改PPTX文件中文本框格式

    问题描述:最近正在整理Python教材的配套PPT,原来的PPT是4:3的,考虑到现在很多屏幕都是宽屏的,于是打算重新整理一下.对于正常的幻灯片,直接在"页面设置"中修改一下就可以 ...

  5. python批量修改替换文件内容

    1.python批量修改文件内容 import os def replaceFileContent(filepath1, content1, replaceContent1):f = open(fil ...

  6. Python批量修改单个文件夹文件后缀

    今天下载了视频,但是视频格式是.mkv的,唱戏机不支持mkv格式,所以需要将后缀改成.mp4(其他文件格式也可以),由于视频比较多一个一个的更改比较麻烦,所以想到了用python来进行批量修改. 首先 ...

  7. python批量修改doc文件

    最近公司有个项目改名了,所以以前的文档也要全部修改. 大部分文档都需要改个名字,而大部分文档要修改的内容也是将文档的名字替换,此外就没了其他要修改的内容. 这样的情况下去一个一个操作文件时很费时间的, ...

  8. python批量修改Excel文件后缀csv为xlsx

    可以实现功能,转换后的文件可能有字体被加粗之类的问题,转换后需要检查一下. csv_xlsx.py import osimport pandas as pddef csv_to_excel(readp ...

  9. Python使用三种方法批量修改记事本文件编码格式

    应用背景:近期计划写一个贝叶斯算法邮件分类的教学案例,苦于没有足够的训练集,就让同学们帮忙每人从自己的邮箱中找几封垃圾邮件把内容复制下来放到记事本文件中发给我,但是忘了提前统一编码格式要求,所以收到的 ...

最新文章

  1. 对python源码进行编译,加密python脚本
  2. 给Ubuntu 16.04更换更新源
  3. 田忌赛马贪心算法_acm田忌赛马问题在线等急求!!
  4. mongodb4简明笔记
  5. 格力电器开始向“电动口罩”发力了?
  6. Java语言的基础知识6
  7. Bailian4075 矩阵旋转【矩阵】
  8. 完善的WebGis地图编辑器
  9. 自制VBS自动刷屏器,再也不怕刷屏刷不过别人了
  10. python实现你说我猜游戏
  11. summit超级计算机gpu温度,揭秘Summit:加速计算赋力全球最快超级计算机
  12. Maven镜像(mirror)
  13. dtu转发虚拟服务器,DTU转发云服务器
  14. 【解决方法】iOS 开发小技巧(一)
  15. APS车间排产软件实现企业生产数据可视化
  16. python办公自动化价值是什么意思_用python进行办公自动化都需要学习什么知识呢?...
  17. 最火后台管理系统 RuoYi 项目探秘,之二
  18. Sketch for mac(矢量绘图UI设计软件)91中文最新版
  19. vue h5 腾讯地图路线规划
  20. Spring和WebSocket整合并建立简单的Web聊天室

热门文章

  1. php-过滤不可见零宽的字符\u200B
  2. 基于STM32F103单片机WIFI无线APP控灯亮度灭设计
  3. STM32的书由三部分组成:主控,串行总线,外设传感器
  4. Comcast将与EA联手推出机顶盒在线游戏效劳
  5. 元宇宙中六大可能出现的法律问题
  6. python学习笔记 - 设置Excel单元格样式
  7. ArcGIS应用分析--学校选址
  8. win10电脑打开此电脑、资源管理器、任务管理器软件等突然很慢很慢,cup、内存、磁盘利用率却很低
  9. 闲暇时间看了下DHT网络
  10. [NOI2005]瑰丽华尔兹 动态规划 + 单调队列