我有像这样的json文件
{"lomx": "3 lokan", "idx": "kojemany94AaABAg", "moraku": "loerlaosjdis hejuyasdb", "keyword": "mekanobhaemausjek14232", "subhen": "koshdeksad"}
{"lomx": "3 lokan", "idx": "kojemany94AaABAg", "moraku": "londasjhdj", "keyword": "mekanobhaemausjek223232323", "subhen": "uahdioasdohoasd"}
{"lomx": "4 lokan", "idx": "jhalskdjhakljdisoaj", "moraku": "vajdlajd", "keyword": "mekanobhaemausjek3242312345", "subhen": "jshdajshdajhsdjhaksdjhsjdkahsdjkah"}
{"lomx": "4 lokan", "idx": "jahdjheuhasndashduasd", "moraku": "morkajsdhu", "keyword": "mekanobhaemausjek273232323232", "subhen": "lokamajuaksdksdasdaahsjdhkajhsdjkahs"}
我需要提取“关键字”的所有单个值,并逐行将其添加到文本文件中
结果应该是这样的
mekanobhaemausjek14232
mekanobhaemausjek223232323
mekanobhaemausjek3242312345
mekanobhaemausjek273232323232
这就是我试过的
import json
data_file = 'c:\json_file.json'
json_data = open(data_file)
parsed_json = json.loads(json_data)
for mydata in parsed_json['keyword']
print (mydata)
f = open('jessers.txt','a')
f.write("%s\n" % mydata)
f.close()
答案 0 :(得分:1)
看来你的程序有一点问题,下面是我的测试。现在没有错误。也许你可以修改它以满足你的需要。
mekanobhaemausjek14232
mekanobhaemausjek223232323
mekanobhaemausjek3242312345
mekanobhaemausjek273232323232
输出:
let gameScene:GameScene = GameScene(size: self.size)
gameScene.scaleMode = self.scaleMode