Last active
November 5, 2018 17:50
-
-
Save allanjos/f7dd3b6ac7afcb8d5df65bc22f5c9ab8 to your computer and use it in GitHub Desktop.
Python / JSON / Hash / Array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
jsonStr = '[{"one" : "1", "two" : "2", "three" : "3"}]'; | |
print "Parsing json " + jsonStr | |
listData = json.loads(jsonStr) | |
print "Direct access:" | |
print "\tone = " + listData[0]['one'] | |
print "\ttwo = " + listData[0]['two'] | |
print "\tthree = " + listData[0]['three'] | |
print "Iteration over hash:" | |
for hashDataElement in listData: | |
for key in hashDataElement: | |
print "\t" + key + ": " + hashDataElement[key] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment