>>> import json
>>>
>>> jsonString = """[
... {"firstName":"John", "lastName":"Doe"},
... {"firstName":"Anna", "lastName":"Smith"},
... {"firstName":"Angel", "lastName":"Cool"}
... ]"""
>>>
>>>
>>> print jsonString
[
{"firstName":"John", "lastName":"Doe"},
{"firstName":"Anna", "lastName":"Smith"},
{"firstName":"Angel", "lastName":"Cool"}
]
>>>
>>> data = json.loads(jsonString)
>>>
>>> print data[2]['firstName']
Angel
>>> print data[2]['lastName']
Cool
>>>
>>> type(data)
<type 'list'>
>>>
>>>
>>> for person in data:
... print person['firstName'] + ' ' + person['lastName']
...
John Doe
Anna Smith
Angel Cool
>>>
>>> data.reverse()
>>>
>>> for person in data:
... print person['firstName'] + ' ' + person['lastName']
...
Angel Cool
Anna Smith
John Doe
>>>
Reversing strings:
>>> print 'Donald Trump'[::-1]
pmurT dlanoD
>>> print 'lion oil'[::-1]
lio noil
>>> print 'A car, a man, a maraca.'[::-1]
.acaram a ,nam a ,rac A
Comments
Comments are not available for this entry.