python遍历JSON文件,将某字段按行存入txt文件

import json
#读取json文件,提取诗词内容逐行放入txt文档
with open("poem.json", 'r', encoding='utf-8') as f:
  temp = json.loads(f.read())
  for item in temp:
    if len(item['paragraphs'])!=0:
      str = ''
      for i in item['paragraphs']:
        str = str + i
      with open("poem.txt", 'a', encoding='utf-8') as f:
        f.write(str+"\n")
  print(index)

你可能感兴趣的:(python遍历JSON文件,将某字段按行存入txt文件)