我有一个 API,它的响应是这样的 json:
{
"a":1,
"b":2,
"c":[
{
"d":4,
"e":5,
"f":{
"g":6
}
}
]
}
Run Code Online (Sandbox Code Playgroud)
我怎样才能编写一个 python 程序,它会给我钥匙['d','e','g']
。我试过的是:
jsonData = request.json() #request is having all the response which i got from api
c = jsonData['c']
for i in c.keys():
key = key + str(i)
print(key)
Run Code Online (Sandbox Code Playgroud) 我想创建一个 json 文件,例如
{
"a":["12","34","23",...],
"b":["13","14","45",....],
.
.
.
}
Run Code Online (Sandbox Code Playgroud)
密钥应来自列表:
lis = ['a','b',...]
Run Code Online (Sandbox Code Playgroud)
以及来自 sql 查询“select id from”+ i 的值,我在其中通过“i”迭代列表。该查询仅返回列 ID。
这是示例代码:
lis = ['a','b','c']
len_obj = len(lis)
with open("Dataset.json", 'w') as file:
for i in lis:
file.write(i)
obj_query = i + '_query'
obj_query = sf.query("select id from " + i)
jsondata = json.loads(json.dumps(obj_query['records']))
length = len(jsondata)
i = {}
k = 0
for j in range(length):
obj_id = jsondata[j]['Id']
# print("id " + obj_id)
if k == 0: …
Run Code Online (Sandbox Code Playgroud)