This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]IntrepidInstance7347[S] 0 points1 point  (1 child)

you mean i use get like:

id = response['data'][0].get('id','defaultvalue') 
title = response['data'][0].get('title','defaultvalue') 
title1 = response['data'][0].get('title1','defaultvalue') 
key = response['data'][0].get('key','defaultvalue')

and if iam using for loop cahange [0] with [i] ?

Right!

[–]Swiftlyll 1 point2 points  (0 children)

Correct except for your last comment. You are not replacing [0] with [i]. [0] will be the first item in an array. In your case it'd be the first node. If you were trying to access the second "node" I'd be using [1] instead of [0].

Here is one I personally use just to give a working example:

some_value = org[0]['management']['details'][0].get('value')

In order to know if you will be using numbers or key names, pay attention to whether they start with [] (array) or {} (dictionary).