python - How do I return a specific json field? -


how function return value "accounting"?

def getowner():        z = [{u'_ref': u'network/zg5zlm5ldhdvcmskmtaumtawljewmc4wlz90jlza:10.100.100.0/24/default', u'extattrs': {u'owner': {u'value': u'accounting'}}}]        return ((h['value']) h in z['owner'])   z = getowner() print z 

im getting error typeerror: list indices must integers, not str

your z variable array (of 1 element) because of surrounding square brackets. here how access have:

>>> z[0]['extattrs']['owner']['value'] u'accounting' 

Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -