python json
1.将字典转化为json
json.dumps()
>>> import json >>> dict = {'name':'zhaolibin','age':20,'sex':'boy'} >>> json_data = json.dumps(dict,indent=4,separators=(',',': '),sort_keys=True) >>> print json_data { "age": 20, "name": "zhaolibin", "sex": "boy" }
2.json.loads
>>> jsonData = '{"number": 6, "name": "Pythontab"}' >>> str = json.loads(jsonData) >>> print str {u'number': 6, u'name': u'Pythontab'} >>> print type(str) <type 'dict'>