# coding:utf
import json
def test_dict_output():
a_dict = {'a': u'你好',
'b': u'中国'}
a_dict_str = json.dumps(a_dict, ensure_ascii=False).encode('utf-8')
print(a_dict_str)
def test_list_output():
a_list = [u'你好', u'中国']
print(' '.join(a_list))
print(str(a_list).decode('unicode-escape'))
print(json.dumps(a_list, ensure_ascii=False))
if __name__ == '__main__':
test_dict_output()
test_list_output()
{"a": "你好", "b": "中国"}
你好 中国
[u'你好', u'中国']
["你好", "中国"]
本文介绍了一段使用 Python 处理 JSON 数据的代码实例,包括如何将包含中文的字典和列表转换为 JSON 字符串,并展示了不同输出方式的效果。
2503

被折叠的 条评论
为什么被折叠?



