python string (json format) to dict
JSON to Python dict
dictinfo = simplejson.loads(json_str) # output as a dict typepython dict to JSON:
jsoninfo = simplejson.dumps(dict) ## output as a string typeExamples:
info = {'name' : 'jay', 'sex' : 'male', 'age': 22}jsoninfo = simplejson.dumps(info)
print jsoninfo
print type(jsoninfo)
PS: another tip is that you can use eval, try eval(json_str), which will return a python dict type.
Post a Comment