Created
January 29, 2012 14:58
-
-
Save clowwindy/1699170 to your computer and use it in GitHub Desktop.
json to Python object
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
input_str = "{'a':[{'b':'1','d':'3',},{'b':'2','d'='a'},{'b':'3','d':'4'}],'c':'1'}" | |
import json | |
class storage(object): | |
def __init__(self, dct): | |
self.__dict__ = dct | |
result = json.loads(input_str.replace("'",'"').replace("=", ":").replace(",}","}"), object_hook=storage) | |
print result.a[0].b | |
print result.a[1].d | |
print result.c |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment