输入测试.json-你知道吗
{"strikers": [
{ "name": "Alexis Sanchez", "club": "Manchester United" },
{ "name": "Robin van Persie", "club": "Feyenoord" }
] }
test1.json文件
{"strikers": [
{ "name": "Nicolas Pepe", "club": "Arsenal" }
] }
预期产量结果.json你知道吗
{"strikers": [
{ "name": "Alexis Sanchez", "club": "Manchester United" },
{ "name": "Robin van Persie", "club": "Feyenoord" },
{ "name": "Nicolas Pepe", "club": "Arsenal" }
] }
我的输出
{"strikers": [
{ "name": "Alexis Sanchez", "club": "Manchester United" },
{ "name": "Robin van Persie", "club": "Feyenoord" }
] },
{"strikers": [
{ "name": "Nicolas Pepe", "club": "Arsenal" }
] }
我已经写了这段代码,不知道如何前进。有人能帮我吗?你知道吗
def mangle(s):
return s.strip()[1:-1]
input_filenames = ["test.json", "test1.json"]
with file("result.json", "w") as outfile:
first = True
for infile_name in input_filenames:
with file(infile_name) as infile:
if first:
outfile.write('[')
first = False
else:
outfile.write(',')
outfile.write(mangle(infile.read()))
outfile.write(']')
交互式演示:https://repl.it/repls/DullBeneficialConcentrate
你知道吗结果.json地址:
使用
json.load()
解析JSON,使用json.dump()
编写JSON。然后连接属性。你知道吗这段代码假设JSON中的所有属性都是需要连接的列表。你知道吗
python有一个有用的
json
库,您可以这样做:这个指纹
相关问题 更多 >
编程相关推荐