简体   繁体   中英

Simple way to extract key and values data from nested Json Response

Hello everyone here is a snippet of my nested json Response.

https://pastebin.com/qTk21iwX

What I want to accomplished to get all the "Row" data from this json response but I have yet to figure out the correct method of approaching this.

This is what I have tried is:

 response = requests.get(url, headers=headers, json={"script": sql}, verify=verify).json()
print(response)
responseobject = json.dumps(response)
print(responseobject)

for object in responseobject['Result']['Results']:
    print (object)

My output after running this code

TypeError: string indices must be integers

Any suggestions ?

responseobject = json.dumps(response)

Here you are turning the response object into a string. So when you do responseobject['Result'] , you are indexing a string, not a dictionary.

To fix the problem, just remove responseobject = json.dumps(response) and do response['Result']['Results'] instead of responseobject['Result']['Results'] .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM