import json
a = {'a': 123, 'b': 456, 'c': 'pen'}
print json.dumps(a)
# 输出:{"a": 123, "c": "pen", "b": 456}
print type(json.dumps(a))
# 输出:
# -*- coding: utf-8 -*-
import json
dict = {"a": 1, "b": {"list":[1,2,3],"str":"hello"}, "c": 3}
formatJson = json.dumps(dict, indent=2, separators=(',', ':'))
print formatJson
fileWriter = open("D:/text.json", 'w')
fileWriter.write(formatJson)
import json
a = '{"a": 123, "b": 456, "c": "pen"}'
print json.loads(a)
# 输出:{u'a': 123, u'c': u'pen', u'b': 456}
print type(json.loads(a))
# 输出:
import json
jsonInfo = {"a": 123, "b": 456, "c": "pen"}
a = open('D:\why.json', 'w')
json.dump(jsonInfo, a)
import json
a = open('D:\why.json', 'r')
info = json.load(a)
print(info)
# 输出:{"a": 123, "b": 456, "c": "pen"}
print type(info)
# 打印出的是Unicode字符串(Python六种内建类型之一)
# 输出:
json.dumps(data_dict, ensure_ascii=False)