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
Post a Comment