Posted in Python onNovember 30, 2017
本文实例讲述了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 json with 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简单读取json文件功能示例
- Author -
HeatDeath声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Reply on: @reply_date@
@reply_contents@