本文实例讲述了Python简单读取json文件功能。分享给大家供大家参考,具体如下:
read_json.json:
{ "rule":{ "namespace":"strategy", "name":"test_exp_1496234234223400", "version":0, "last_modify_time":1434234236819000, "log_rate":1023300, "schema_version":"hello_world!" }}
read_json.py:
# -*- coding:utf-8 -*-import jsonwith open("read_json.json", 'r') as f: temp = json.loads(f.read()) print(temp) print(temp['rule']) print(temp['rule']['namespace'])
运行结果:
{u'rule': {u'name': u'test_exp_1496234234223400', u'log_rate': 1023300, u'namespace': u'strategy', u'schema_version': u'hello_world!', u'last_modify_time': 1434234236819000L, u'version': 0}}{u'name': u'test_exp_1496234234223400', u'log_rate': 1023300, u'namespace': u'strategy', u'schema_version': u'hello_world!', u'last_modify_time': 1434234236819000L, u'version': 0}strategy
希望本文所述对大家Python程序设计有所帮助。
新闻热点
疑难解答