我知道我在这里忽略了显而易见的东西,但是我有下面的PYTHON代码,我正在尝试-
import json
def OpenJsonFileAndPullData (JsonFileName, JsonOutputFileName):
output_file=open(JsonOutputFileName, 'w')
result = []
with open(JsonFileName, 'r') as InputFile:
for line in InputFile:
Item=json.loads(line)
my_dict={}
print item
my_dict['Post Content']=item.get('content_text')
my_dict['Type of Post']=item.get('content_type')
print my_dict
result.append(my_dict)
json.dumps(result, output_file)
OpenJsonFileAndPullData ('MyInput.json', 'MyOutput.txt')
但是,运行时我收到以下错误:
AttributeError: 'str' object has no attribute 'get'
Python区分大小写。你知道吗
顺便问一下,为什么不一次将整个文件作为json加载?你知道吗
相关问题 更多 >
编程相关推荐