标签:log 合成 https com class imp code org 字符
#!/usr/bin/python3
import json
mytest_js = {
"a" : 1,
"b" : 2
}
test = json.dumps({'4': 5, '6': 7}); # 合成不换行的字符串 json 数据
test1 = json.dumps({'4': 5, '6': 7}, sort_keys = True, indent = 4, separators = (',', ':')); # 合成有换行的字符串数据
mytest_jsson = json.dumps(mytest_js); # 解析出 json 格式的字符串
print(test);
print("");
print(test1);
print("");
print(mytest_jsson);
// 输出
{"4": 5, "6": 7}
{
"4":5,
"6":7
}
{"a": 1, "b": 2}
test1 = json.dumps({'4': 5, '6': 7}, sort_keys = True, indent = 4, separators = (',', ':')); # 先合成为字符串
text = json.loads(test1); # 后转化为对象输出
print(text);
print(text['4']);
print(text['6']);
{'4': 5, '6': 7}
5
7
https://docs.python.org/2/library/json.html
http://www.runoob.com/python/python-json.html
http://www.runoob.com/python3/python3-json.html
标签:log 合成 https com class imp code org 字符
原文地址:http://www.cnblogs.com/chenfulin5/p/7834466.html