修改json格式的数据文件为txt格式

Posted yandyand

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了修改json格式的数据文件为txt格式相关的知识,希望对你有一定的参考价值。

import json
path = r"H:weibo4sdc-907869a8-212f-11e8-9a3e-ab0426199701_77a6516b-4816-40cf-beaf-cc5d31f07e41" #:文件位置
file = open(path, ‘r‘, encoding=‘utf-8‘) #:打开文件
file1 = open(r"H:ceshi est4.txt", ‘a‘,encoding="utf-8") #:打开.text文件

for line in file.readlines(): #:按照列表方式读取文件
fileJson = json.loads(line) #:转义为字典
#:拿取值 key/values
key = fileJson["key"]
asp = fileJson["asp"]
ID = fileJson["id"]
nfc = fileJson["nfc"]
uau = fileJson["uau"]
ubi = fileJson["ubi"]
ubstat = fileJson["ubstat"]
ubu = fileJson["ubu"]
udes = fileJson["udes"]
ufc = fileJson["ufc"]
ufcn = fileJson["ufcn"]
ugen = fileJson["ugen"]
ugt = fileJson["ugt"]
uid = fileJson["uid"]
uim = fileJson["uim"]
uip = fileJson["uip"]
uit = fileJson["uit"]
uiu = fileJson["uiu"]
uiv = fileJson["uiv"]
ulan = fileJson["ulan"]
ulc = fileJson["ulc"]
uloc = fileJson["uloc"]
ulp = fileJson["ulp"]
umc = fileJson["umc"]
una = fileJson["una"]
unn = fileJson["unn"]
urem = fileJson["urem"]
upti = fileJson["upti"]
urn = fileJson["urn"]
urt = fileJson["urt"]
ust = fileJson["ust"]
uuo = fileJson["uuo"]
uut = fileJson["uut"]
uvi = fileJson["uvi"]
uvip = fileJson["uvip"]
file1.write(
str(key) + "," + str(asp) + "," + str(ID) + "," + str(nfc) + "," + str("uau") + "," + str(ubi) + "," + str(ubstat) + "," + str(ubu) + "" + str(udes) + "" + str(ufc) + "," + str(ufcn) + "," +
str(ugen) + "," + str(ugt) + "," + str(uid) + "," + str(uim) + "," + str(uip) + "," + str(uit) + "," + str(uiu) + "," + str(uiv) + "," + str(ulan) + "" + str(ulc) + "," + str(uloc) + "," +
str(ulp) + "," + str(umc) + "," + str(una) + "" + str(unn) + "," + str(upti) + "," + str(urem) + "" + str(urn) + "" + str(urt) + "," + str(ust) + "," + str(uuo) + "," + str(uut) + "," + str(uvi) + "" + str(uvip)
)
file1.write(" ")

print("导入完毕!")

以上是关于修改json格式的数据文件为txt格式的主要内容,如果未能解决你的问题,请参考以下文章

目标检测数据集转换 json文件转换为txt文件格式

PySpark 从目录中读取多个 txt 文件为 json 格式

python实现将json数据以json格式写入txt文件

json为txt文本加密

.db3格式文件怎么打开或转换为.txt或.xls文件

使用 PHP 将 txt 数据文件转换为结构化 JSON